From bf19eb2ec5977a389538cff23b2041b27ec10011 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 23 Jul 2020 10:27:21 +0200 Subject: [PATCH] [refactor] minor code cleanup --- egui/src/containers/resize.rs | 2 -- egui/src/context.rs | 2 +- egui/src/examples/app.rs | 5 ----- egui/src/input.rs | 6 ------ egui/src/layout.rs | 4 ++-- egui/src/paint.rs | 4 ++-- egui/src/paint/fonts.rs | 4 ++-- egui/src/paint/{mesher.rs => tessellator.rs} | 14 ++++---------- egui/src/types.rs | 10 +++++----- 9 files changed, 16 insertions(+), 35 deletions(-) rename egui/src/paint/{mesher.rs => tessellator.rs} (98%) diff --git a/egui/src/containers/resize.rs b/egui/src/containers/resize.rs index 57aa1c82..568cc792 100644 --- a/egui/src/containers/resize.rs +++ b/egui/src/containers/resize.rs @@ -1,5 +1,3 @@ -#![allow(unused_variables)] // TODO - use crate::*; #[derive(Clone, Copy, Debug)] diff --git a/egui/src/context.rs b/egui/src/context.rs index 889fe66d..33af0013 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -191,7 +191,7 @@ impl Context { let paint_commands = self.drain_paint_lists(); let num_primitives = paint_commands.len(); let paint_jobs = - mesher::paint_commands_into_triangles(paint_options, self.fonts(), paint_commands); + tessellator::tessellate_paint_commands(paint_options, self.fonts(), paint_commands); { let mut stats = PaintStats::default(); diff --git a/egui/src/examples/app.rs b/egui/src/examples/app.rs index c4b3e006..245ade63 100644 --- a/egui/src/examples/app.rs +++ b/egui/src/examples/app.rs @@ -1,4 +1,3 @@ -// #![allow(dead_code, unused_variables)] // should be commented out use std::sync::Arc; use crate::{color::*, containers::*, examples::FractalClock, widgets::*, *}; @@ -37,10 +36,6 @@ impl ExampleApp { } pub fn windows(&mut self, ctx: &Arc) { - // TODO: Make it even simpler to show a window - - // TODO: window manager for automatic positioning? - let ExampleApp { open_windows, example_window, diff --git a/egui/src/input.rs b/egui/src/input.rs index 237ee9fe..abe37160 100644 --- a/egui/src/input.rs +++ b/egui/src/input.rs @@ -8,8 +8,6 @@ const MAX_CLICK_DELAY: f64 = 0.3; /// What the integration gives to the gui. /// All coordinates in egui is in point/logical coordinates. #[derive(Clone, Debug, Default)] -#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))] -#[cfg_attr(feature = "with_serde", serde(default))] pub struct RawInput { /// Is the button currently down? pub mouse_down: bool, @@ -154,8 +152,6 @@ impl Default for MouseInput { } #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] -#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))] -#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] pub enum Event { Copy, Cut, @@ -168,8 +164,6 @@ pub enum Event { } #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] -#[cfg_attr(feature = "with_serde", derive(serde::Deserialize))] -#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] pub enum Key { Alt, Backspace, diff --git a/egui/src/layout.rs b/egui/src/layout.rs index 1474a165..d5ee5189 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -4,7 +4,7 @@ use crate::{math::*, style::Style}; #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] - +#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] pub enum Direction { Horizontal, Vertical, @@ -56,7 +56,7 @@ pub fn align_rect(rect: Rect, align: (Align, Align)) -> Rect { // ---------------------------------------------------------------------------- #[derive(Clone, Copy, Debug, PartialEq)] -#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +// #[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Layout { /// Lay out things horizontally or vertically? dir: Direction, diff --git a/egui/src/paint.rs b/egui/src/paint.rs index 61ac7468..05796558 100644 --- a/egui/src/paint.rs +++ b/egui/src/paint.rs @@ -2,13 +2,13 @@ pub mod color; pub mod command; pub mod font; pub mod fonts; -pub mod mesher; +pub mod tessellator; mod texture_atlas; pub use { color::Color, command::{LineStyle, PaintCmd}, fonts::{FontDefinitions, Fonts, TextStyle}, - mesher::{PaintJobs, PaintOptions, Path, Triangles, Vertex}, + tessellator::{PaintJobs, PaintOptions, Path, Triangles, Vertex}, texture_atlas::Texture, }; diff --git a/egui/src/paint/fonts.rs b/egui/src/paint/fonts.rs index 80784a21..841603e5 100644 --- a/egui/src/paint/fonts.rs +++ b/egui/src/paint/fonts.rs @@ -13,7 +13,7 @@ use super::{ /// TODO: rename #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +// #[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub enum TextStyle { Body, Button, @@ -22,7 +22,7 @@ pub enum TextStyle { } #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] +// #[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub enum FontFamily { Monospace, VariableWidth, diff --git a/egui/src/paint/mesher.rs b/egui/src/paint/tessellator.rs similarity index 98% rename from egui/src/paint/mesher.rs rename to egui/src/paint/tessellator.rs index f716ea94..638f49fc 100644 --- a/egui/src/paint/mesher.rs +++ b/egui/src/paint/tessellator.rs @@ -1,7 +1,3 @@ -// TODO: rename tessellator - -#![allow(clippy::identity_op)] - /// Outputs render info in a format suitable for e.g. OpenGL. use { super::{ @@ -15,7 +11,6 @@ use { const WHITE_UV: (u16, u16) = (1, 1); #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Vertex { /// Pixel coordinates pub pos: Pos2, @@ -26,7 +21,6 @@ pub struct Vertex { } #[derive(Clone, Debug, Default)] -#[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Triangles { /// Draw as triangles (i.e. the length is a multiple of three) pub indices: Vec, @@ -558,7 +552,7 @@ fn mul_color(color: Color, factor: f32) -> Color { // ---------------------------------------------------------------------------- /// `reused_path`: only used to reuse memory -pub fn paint_command_into_triangles( +pub fn tessellate_paint_command( reused_path: &mut Path, options: PaintOptions, fonts: &Fonts, @@ -675,7 +669,7 @@ pub fn paint_command_into_triangles( } /// Turns `PaintCmd`:s into sets of triangles -pub fn paint_commands_into_triangles( +pub fn tessellate_paint_commands( options: PaintOptions, fonts: &Fonts, commands: Vec<(Rect, PaintCmd)>, @@ -691,12 +685,12 @@ pub fn paint_commands_into_triangles( } let out = &mut jobs.last_mut().unwrap().1; - paint_command_into_triangles(&mut reused_path, options, fonts, cmd, out); + tessellate_paint_command(&mut reused_path, options, fonts, cmd, out); } if options.debug_paint_clip_rects { for (clip_rect, triangles) in &mut jobs { - paint_command_into_triangles( + tessellate_paint_command( &mut reused_path, options, fonts, diff --git a/egui/src/types.rs b/egui/src/types.rs index f11eab4d..f6f6e573 100644 --- a/egui/src/types.rs +++ b/egui/src/types.rs @@ -5,7 +5,7 @@ use crate::{math::Rect, Context, Ui}; // ---------------------------------------------------------------------------- #[derive(Clone, Default)] -#[cfg_attr(feature = "with_serde", derive(serde::Serialize))] +// #[cfg_attr(feature = "with_serde", derive(serde::Serialize))] pub struct Output { pub cursor_icon: CursorIcon, @@ -22,8 +22,8 @@ pub struct Output { } #[derive(Clone, Copy)] -#[cfg_attr(feature = "with_serde", derive(serde::Serialize))] -#[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] +// #[cfg_attr(feature = "with_serde", derive(serde::Serialize))] +// #[cfg_attr(feature = "with_serde", serde(rename_all = "snake_case"))] pub enum CursorIcon { Default, /// Pointing hand, used for e.g. web links @@ -44,7 +44,7 @@ impl Default for CursorIcon { // ---------------------------------------------------------------------------- #[derive(Clone, Copy, Debug)] -#[cfg_attr(feature = "with_serde", derive(serde::Serialize))] +// #[cfg_attr(feature = "with_serde", derive(serde::Serialize))] pub struct InteractInfo { /// The senses (click or drag) that the widget is interested in (if any). pub sense: Sense, @@ -147,7 +147,7 @@ impl Into for GuiResponse { /// What sort of interaction is a widget sensitive to? #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "with_serde", derive(serde::Serialize))] +// #[cfg_attr(feature = "with_serde", derive(serde::Serialize))] pub struct Sense { /// buttons, sliders, windows ... pub click: bool,