From 598564cecc4b0cb37bf7026505f837b2c2999623 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 May 2020 11:16:31 +0200 Subject: [PATCH] Fix some clippy issues --- egui/src/containers/collapsing_header.rs | 6 +----- egui/src/containers/window.rs | 22 ++++++++++------------ egui/src/context.rs | 6 +++--- egui/src/examples/app.rs | 2 -- egui/src/layout.rs | 8 ++++---- egui/src/math.rs | 2 +- egui/src/memory.rs | 2 +- egui/src/paint/font.rs | 11 ++++++++--- egui/src/paint/mesher.rs | 12 +++++++----- egui/src/style.rs | 2 +- egui/src/ui.rs | 2 +- egui/src/widgets/text_edit.rs | 2 +- 12 files changed, 38 insertions(+), 39 deletions(-) diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index e027cc8d..3f93e5b9 100644 --- a/egui/src/containers/collapsing_header.rs +++ b/egui/src/containers/collapsing_header.rs @@ -31,14 +31,10 @@ impl Default for State { impl State { pub fn from_memory_with_default_open(ui: &Ui, id: Id, default_open: bool) -> Self { - ui.memory() - .collapsing_headers - .entry(id) - .or_insert(State { + *ui.memory().collapsing_headers.entry(id).or_insert(State { open: default_open, ..Default::default() }) - .clone() } // Helper diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 0a85537c..c51352ae 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -193,7 +193,7 @@ impl<'open> Window<'open> { let default_expanded = true; let mut collapsing = collapsing_header::State::from_memory_with_default_open( - &mut frame.content_ui, + &frame.content_ui, collapsing_id, default_expanded, ); @@ -244,15 +244,13 @@ impl<'open> Window<'open> { interaction, ctx.style().interact.active, ); - } else { - if let Some(hover_interaction) = hover_interaction { - paint_frame_interaction( - &mut area_content_ui, - outer_rect, - hover_interaction, - ctx.style().interact.hovered, - ); - } + } else if let Some(hover_interaction) = hover_interaction { + paint_frame_interaction( + &mut area_content_ui, + outer_rect, + hover_interaction, + ctx.style().interact.hovered, + ); } } let full_interact = area.end(ctx, area_content_ui); @@ -357,7 +355,7 @@ fn resize_window(ctx: &Context, window_interaction: &WindowInteraction) -> Optio rect = rect.translate(mouse_pos - ctx.input().mouse.press_origin?); } - return Some(rect); + Some(rect) } fn window_interaction( @@ -375,7 +373,7 @@ fn window_interaction( } } - let mut window_interaction = { ctx.memory().window_interaction.clone() }; + let mut window_interaction = { ctx.memory().window_interaction }; if window_interaction.is_none() { if let Some(hover_window_interaction) = resize_hover(ctx, possible, area_layer, rect) { diff --git a/egui/src/context.rs b/egui/src/context.rs index 243b5013..867c1314 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -106,7 +106,7 @@ impl Context { // TODO: return MutexGuard pub fn style(&self) -> Style { - *self.style.try_lock().expect("style already locked") + self.style.try_lock().expect("style already locked").clone() } pub fn set_style(&self, style: Style) { @@ -303,14 +303,14 @@ impl Context { active: false, }; - if sense.click && !memory.interaction.click_id.is_some() { + if sense.click && memory.interaction.click_id.is_none() { // start of a click memory.interaction.click_id = Some(interaction_id); info.active = true; } if sense.drag - && (!memory.interaction.drag_id.is_some() || memory.interaction.drag_is_window) + && (memory.interaction.drag_id.is_none() || memory.interaction.drag_is_window) { // start of a drag memory.interaction.drag_id = Some(interaction_id); diff --git a/egui/src/examples/app.rs b/egui/src/examples/app.rs index 8b6b441d..c538853e 100644 --- a/egui/src/examples/app.rs +++ b/egui/src/examples/app.rs @@ -90,7 +90,6 @@ impl ExampleApp { struct OpenWindows { // examples: examples: bool, - example_tree: bool, fractal_clock: bool, // egui stuff: @@ -112,7 +111,6 @@ impl OpenWindows { fn none() -> Self { Self { examples: false, - example_tree: true, fractal_clock: false, settings: false, diff --git a/egui/src/layout.rs b/egui/src/layout.rs index 1c719191..1474a165 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -125,17 +125,17 @@ impl Layout { } } - pub fn dir(&self) -> Direction { + pub fn dir(self) -> Direction { self.dir } - pub fn is_reversed(&self) -> bool { + pub fn is_reversed(self) -> bool { self.reversed } /// Given the cursor in the region, how much space is available /// for the next widget? - pub fn available(&self, cursor: Pos2, rect: Rect) -> Rect { + pub fn available(self, cursor: Pos2, rect: Rect) -> Rect { if self.reversed { Rect::from_min_max(rect.min, cursor) } else { @@ -156,7 +156,7 @@ impl Layout { /// /// You may get LESS space than you asked for if the current layout won't fit what you asked for. pub fn allocate_space( - &self, + self, cursor: &mut Pos2, style: &Style, available_size: Vec2, diff --git a/egui/src/math.rs b/egui/src/math.rs index 8a6e744c..ddc8b96a 100644 --- a/egui/src/math.rs +++ b/egui/src/math.rs @@ -65,7 +65,7 @@ impl Vec2 { } /// Use this vector as a rotor, rotating something else. - /// Example: Vec2::angled(angle).rotate_other(some_vec) + /// Example: `Vec2::angled(angle).rotate_other(some_vec)` #[must_use] pub fn rotate_other(self, v: Vec2) -> Self { Self { diff --git a/egui/src/memory.rs b/egui/src/memory.rs index df647098..82fde6d5 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -98,7 +98,7 @@ impl Memory { if window_interaction.is_pure_move() { // Throw windows because it is fun: let area_layer = window_interaction.area_layer; - let area_state = self.areas.get(area_layer.id).clone(); + let area_state = self.areas.get(area_layer.id); if let Some(mut area_state) = area_state { area_state.vel = prev_input.mouse.velocity; self.areas.set_state(area_layer, area_state); diff --git a/egui/src/paint/font.rs b/egui/src/paint/font.rs index b2700b59..70336fd9 100644 --- a/egui/src/paint/font.rs +++ b/egui/src/paint/font.rs @@ -133,7 +133,7 @@ impl Line { *self.x_offsets.last().unwrap() } - /// Closest char at the desired x coordinate. return [0, char_count()] + /// Closest char at the desired x coordinate. returns something in the range `[0, char_count()]` pub fn char_at(&self, desired_x: f32) -> usize { for (i, char_x_bounds) in self.x_offsets.windows(2).enumerate() { let char_center_x = 0.5 * (char_x_bounds[0] + char_x_bounds[1]); @@ -382,7 +382,7 @@ impl Font { /// Typeset the given text onto one line. /// Assumes there are no \n in the text. - /// Return x_offsets, one longer than the number of characters in the text. + /// Return `x_offsets`, one longer than the number of characters in the text. fn layout_single_line_fragment(&self, text: &str) -> Vec { let scale_in_pixels = Scale::uniform(self.scale_in_pixels); @@ -417,7 +417,12 @@ impl Font { let full_x_offsets = self.layout_single_line_fragment(text); let mut line_start_x = full_x_offsets[0]; - assert_eq!(line_start_x, 0.0); + + { + #![allow(clippy::float_cmp)] + assert_eq!(line_start_x, 0.0); + } + let mut cursor_y = 0.0; let mut line_start_idx = 0; diff --git a/egui/src/paint/mesher.rs b/egui/src/paint/mesher.rs index dce13e2e..8bfeccc3 100644 --- a/egui/src/paint/mesher.rs +++ b/egui/src/paint/mesher.rs @@ -1,3 +1,5 @@ +// TODO: rename tessellator + #![allow(clippy::identity_op)] /// Outputs render info in a format suitable for e.g. OpenGL. @@ -380,7 +382,7 @@ pub fn paint_path_outline( options: PaintOptions, path_type: PathType, path: &[PathPoint], - style: &LineStyle, + style: LineStyle, ) { if style.color == color::TRANSPARENT { return; @@ -574,7 +576,7 @@ pub fn paint_command_into_triangles( fill_closed_path(out, options, &path.0, fill); } if let Some(outline) = outline { - paint_path_outline(out, options, Closed, &path.0, &outline); + paint_path_outline(out, options, Closed, &path.0, outline); } } PaintCmd::Triangles(triangles) => { @@ -582,7 +584,7 @@ pub fn paint_command_into_triangles( } PaintCmd::LineSegment { points, style } => { path.add_line_segment(points); - paint_path_outline(out, options, Open, &path.0, &style); + paint_path_outline(out, options, Open, &path.0, style); } PaintCmd::Path { path, @@ -600,7 +602,7 @@ pub fn paint_command_into_triangles( } if let Some(outline) = outline { let typ = if closed { Closed } else { Open }; - paint_path_outline(out, options, typ, &path.0, &outline); + paint_path_outline(out, options, typ, &path.0, outline); } } } @@ -620,7 +622,7 @@ pub fn paint_command_into_triangles( fill_closed_path(out, options, &path.0, fill); } if let Some(outline) = outline { - paint_path_outline(out, options, Closed, &path.0, &outline); + paint_path_outline(out, options, Closed, &path.0, outline); } } PaintCmd::Text { diff --git a/egui/src/style.rs b/egui/src/style.rs index 134ad0dc..e2fe0dc2 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -3,7 +3,7 @@ use crate::{color::*, math::*, paint::LineStyle, types::*}; // TODO: split into Spacing and Style? -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] #[cfg_attr(feature = "with_serde", derive(serde::Deserialize, serde::Serialize))] pub struct Style { /// Horizontal and vertical padding within a window frame. diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 59fc8c72..e8e66f30 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -82,7 +82,7 @@ impl Ui { clip_rect, desired_rect: child_rect, child_bounds: Rect::from_min_size(child_rect.min, Vec2::zero()), // TODO: Rect::nothing() ? - style: self.style, + style: self.style.clone(), layout: self.layout, cursor: child_rect.min, } diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index d0228fa0..51bb72a4 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -258,5 +258,5 @@ fn line_from_number(s: &str, desired_line_number: usize) -> &str { return line; } } - return s; + s }