From 80cbb5c51a5a819ec57dadd6efce02d5333a34e2 Mon Sep 17 00:00:00 2001 From: genusistimelord Date: Tue, 23 Jan 2024 11:17:00 -0500 Subject: [PATCH] cargo fmt and clippy --- src/core/overlay.rs | 17 ++++++----- src/native/helpers.rs | 6 ++-- src/native/number_input.rs | 32 +++++--------------- src/native/overlay/color_picker.rs | 42 ++++++++++++++------------ src/native/overlay/date_picker.rs | 39 ++++++++++-------------- src/native/overlay/floating_element.rs | 8 ++++- src/native/overlay/time_picker.rs | 15 +++++---- 7 files changed, 74 insertions(+), 85 deletions(-) diff --git a/src/core/overlay.rs b/src/core/overlay.rs index d60bac4c..b427119a 100644 --- a/src/core/overlay.rs +++ b/src/core/overlay.rs @@ -6,20 +6,21 @@ use iced_widget::core::{layout, Point, Size}; pub trait Position { /// Centers this node around the given position. If the node is over the /// specified bounds it's bouncing back to be fully visible on screen. - fn center_and_bounce(self, position: Point, bounds: Size) -> Self; + fn center_and_bounce(&mut self, position: Point, bounds: Size); } impl Position for layout::Node { - fn center_and_bounce(self, position: Point, bounds: Size) -> Self { + fn center_and_bounce(&mut self, position: Point, bounds: Size) { let size = self.size(); - let new_self = self.move_to(Point::new( - (position.x - size.width / 2.0).max(0.0), - (position.y - size.height / 2.0).max(0.0), + + self.move_to_mut(Point::new( + (position.x - (size.width / 2.0)).max(0.0), + (position.y - (size.height / 2.0)).max(0.0), )); - let new_self_bounds = new_self.bounds(); + let new_self_bounds = self.bounds(); - new_self.move_to(Point::new( + self.move_to_mut(Point::new( if new_self_bounds.x + new_self_bounds.width > bounds.width { (new_self_bounds.x - (new_self_bounds.width - (bounds.width - new_self_bounds.x))) .max(0.0) @@ -32,6 +33,6 @@ impl Position for layout::Node { } else { new_self_bounds.y }, - )) + )); } } diff --git a/src/native/helpers.rs b/src/native/helpers.rs index cb7b007f..32c982f7 100644 --- a/src/native/helpers.rs +++ b/src/native/helpers.rs @@ -354,7 +354,8 @@ pub fn selection_list_with<'a, T, Message, Theme, Renderer>( where Message: 'a + Clone, Renderer: 'a + core::Renderer + core::text::Renderer, - Theme: 'a + crate::style::selection_list::StyleSheet + Theme: 'a + + crate::style::selection_list::StyleSheet + iced_widget::container::StyleSheet + iced_widget::scrollable::StyleSheet, T: Clone + Display + Eq + Hash, @@ -383,7 +384,8 @@ pub fn selection_list<'a, T, Message, Theme, Renderer>( where Message: 'a + Clone, Renderer: 'a + core::Renderer + core::text::Renderer, - Theme: 'a + crate::style::selection_list::StyleSheet + Theme: 'a + + crate::style::selection_list::StyleSheet + iced_widget::container::StyleSheet + iced_widget::scrollable::StyleSheet, T: Clone + Display + Eq + Hash, diff --git a/src/native/number_input.rs b/src/native/number_input.rs index 8dd6c0b0..311fef53 100644 --- a/src/native/number_input.rs +++ b/src/native/number_input.rs @@ -454,7 +454,7 @@ where { cursor::State::Index(mut idx) => { if T::zero().eq(&self.value) { - new_val = c.to_string(); + new_val = c.to_owned(); } else { for char in c.chars() { new_val.insert(idx, char); @@ -468,7 +468,7 @@ where { new_val.replace_range( if start > end { end..start } else { start..end }, - &c.to_string(), + c, ); } } @@ -480,14 +480,8 @@ where self.value = val; shell.publish((self.on_change)(self.value)); self.content.on_event( - child, - event.clone(), - content, - cursor, - renderer, - clipboard, - shell, - viewport, + child, event, content, cursor, renderer, clipboard, + shell, viewport, ) } else { event::Status::Ignored @@ -553,14 +547,8 @@ where self.value = val; shell.publish((self.on_change)(self.value)); self.content.on_event( - child, - event.clone(), - content, - cursor, - renderer, - clipboard, - shell, - viewport, + child, event, content, cursor, renderer, + clipboard, shell, viewport, ) } else { event::Status::Ignored @@ -571,13 +559,7 @@ where } } _ => self.content.on_event( - child, - event.clone(), - content, - cursor, - renderer, - clipboard, - shell, + child, event, content, cursor, renderer, clipboard, shell, viewport, ), }, diff --git a/src/native/overlay/color_picker.rs b/src/native/overlay/color_picker.rs index 900838df..b451f550 100644 --- a/src/native/overlay/color_picker.rs +++ b/src/native/overlay/color_picker.rs @@ -476,13 +476,15 @@ where let mut value = i32::from(hsv_color.hue); match key_code { - keyboard::Key::Named(keyboard::key::Named::ArrowLeft) - | keyboard::Key::Named(keyboard::key::Named::ArrowDown) => { + keyboard::Key::Named( + keyboard::key::Named::ArrowLeft | keyboard::key::Named::ArrowDown, + ) => { value -= HUE_STEP; status = event::Status::Captured; } - keyboard::Key::Named(keyboard::key::Named::ArrowRight) - | keyboard::Key::Named(keyboard::key::Named::ArrowUp) => { + keyboard::Key::Named( + keyboard::key::Named::ArrowRight | keyboard::key::Named::ArrowUp, + ) => { value += HUE_STEP; status = event::Status::Captured; } @@ -504,13 +506,15 @@ where let mut status = event::Status::Captured; match key_code { - keyboard::Key::Named(keyboard::key::Named::ArrowLeft) - | keyboard::Key::Named(keyboard::key::Named::ArrowDown) => { + keyboard::Key::Named( + keyboard::key::Named::ArrowLeft | keyboard::key::Named::ArrowDown, + ) => { byte_value -= RGBA_STEP; status = event::Status::Captured; } - keyboard::Key::Named(keyboard::key::Named::ArrowRight) - | keyboard::Key::Named(keyboard::key::Named::ArrowUp) => { + keyboard::Key::Named( + keyboard::key::Named::ArrowRight | keyboard::key::Named::ArrowUp, + ) => { byte_value += RGBA_STEP; status = event::Status::Captured; } @@ -611,9 +615,11 @@ where ) }; - let node = Node::with_children(Size::new(width, height), vec![block1_node, block2_node]); + let mut node = + Node::with_children(Size::new(width, height), vec![block1_node, block2_node]); - node.center_and_bounce(position, bounds) + node.center_and_bounce(position, bounds); + node } fn on_event( @@ -1105,7 +1111,7 @@ fn block2( let rgba_color_layout = block2_children .next() .expect("Graphics: Layout should have a RGBA color layout"); - rgba_color::( + rgba_color( renderer, rgba_color_layout, &color_picker.state.color, @@ -1119,7 +1125,7 @@ fn block2( let hex_text_layout = block2_children .next() .expect("Graphics: Layout should have a hex text layout"); - hex_text::( + hex_text( renderer, hex_text_layout, &color_picker.state.color, @@ -1375,7 +1381,7 @@ fn hsv_color( /// Draws the RGBA color area. #[allow(clippy::too_many_lines)] -fn rgba_color( +fn rgba_color( renderer: &mut Renderer, layout: Layout<'_>, color: &Color, @@ -1383,9 +1389,7 @@ fn rgba_color( style: &renderer::Style, style_sheet: &HashMap, focus: Focus, -) where - Theme: StyleSheet + button::StyleSheet + widget::text::StyleSheet, -{ +) { let mut rgba_color_children = layout.children(); let f = |renderer: &mut Renderer, @@ -1593,7 +1597,7 @@ fn rgba_color( } /// Draws the hex text representation of the color. -fn hex_text( +fn hex_text( renderer: &mut Renderer, layout: Layout<'_>, color: &Color, @@ -1601,9 +1605,7 @@ fn hex_text( _style: &renderer::Style, style_sheet: &HashMap, _focus: Focus, -) where - Theme: StyleSheet + button::StyleSheet + widget::text::StyleSheet, -{ +) { let hsv: Hsv = (*color).into(); let hex_text_style_state = if cursor.is_over(layout.bounds()) { diff --git a/src/native/overlay/date_picker.rs b/src/native/overlay/date_picker.rs index 6727161e..c7f20333 100644 --- a/src/native/overlay/date_picker.rs +++ b/src/native/overlay/date_picker.rs @@ -521,14 +521,15 @@ where y: submit_bounds.y + col.bounds().height + PADDING + SPACING, }); - Node::with_children( + let mut node = Node::with_children( Size::new( col.bounds().width + (2.0 * PADDING), col.bounds().height + cancel_button.bounds().height + (2.0 * PADDING) + SPACING, ), vec![col, cancel_button, submit_button], - ) - .center_and_bounce(position, bounds) + ); + node.center_and_bounce(position, bounds); + node } fn on_event( @@ -782,7 +783,7 @@ where .next() .expect("Graphics: Layout should have a month/year layout"); - month_year::( + month_year( renderer, month_year_layout, &self.month_as_string(), @@ -800,7 +801,7 @@ where .next() .expect("Graphics: Layout should have a days layout"); - days::( + days( renderer, days_layout, self.state.date, @@ -1053,7 +1054,7 @@ impl Default for Focus { } /// Draws the month/year row -fn month_year( +fn month_year( renderer: &mut Renderer, layout: Layout<'_>, month: &str, @@ -1062,9 +1063,7 @@ fn month_year( //style: &Style, style: &HashMap, focus: Focus, -) where - Theme: StyleSheet + button::StyleSheet + container::StyleSheet + text::StyleSheet, -{ +) { let mut children = layout.children(); let month_layout = children @@ -1201,7 +1200,7 @@ fn month_year( } /// Draws the days -fn days( +fn days( renderer: &mut Renderer, layout: Layout<'_>, date: chrono::NaiveDate, @@ -1209,28 +1208,24 @@ fn days( //style: &Style, style: &HashMap, focus: Focus, -) where - Theme: StyleSheet + button::StyleSheet + container::StyleSheet + text::StyleSheet, -{ +) { let mut children = layout.children(); let day_labels_layout = children .next() .expect("Graphics: Layout should have a day labels layout"); - day_labels::(renderer, day_labels_layout, style, focus); + day_labels(renderer, day_labels_layout, style, focus); - day_table::(renderer, &mut children, date, cursor, style, focus); + day_table(renderer, &mut children, date, cursor, style, focus); } /// Draws the day labels -fn day_labels( +fn day_labels( renderer: &mut Renderer, layout: Layout<'_>, style: &HashMap, _focus: Focus, -) where - Theme: StyleSheet + button::StyleSheet + container::StyleSheet + text::StyleSheet, -{ +) { for (i, label) in layout.children().enumerate() { let bounds = label.bounds(); @@ -1256,16 +1251,14 @@ fn day_labels( } /// Draws the day table -fn day_table( +fn day_table( renderer: &mut Renderer, children: &mut dyn Iterator>, date: chrono::NaiveDate, cursor: Point, style: &HashMap, focus: Focus, -) where - Theme: StyleSheet + button::StyleSheet + container::StyleSheet + text::StyleSheet, -{ +) { for (y, row) in children.enumerate() { for (x, label) in row.children().enumerate() { let bounds = label.bounds(); diff --git a/src/native/overlay/floating_element.rs b/src/native/overlay/floating_element.rs index 32f9da7b..09b21a91 100644 --- a/src/native/overlay/floating_element.rs +++ b/src/native/overlay/floating_element.rs @@ -15,7 +15,13 @@ use iced_widget::core::{ /// The internal overlay of a [`FloatingElement`](crate::FloatingElement) for /// rendering a [`Element`](iced_widget::core::Element) as an overlay. #[allow(missing_debug_implementations)] -pub struct FloatingElementOverlay<'a, 'b, Message, Theme = iced_widget::Theme, Renderer = iced_widget::Renderer> { +pub struct FloatingElementOverlay< + 'a, + 'b, + Message, + Theme = iced_widget::Theme, + Renderer = iced_widget::Renderer, +> { /// The state of the element. state: &'b mut Tree, /// The floating element diff --git a/src/native/overlay/time_picker.rs b/src/native/overlay/time_picker.rs index 75db22a7..c73f328b 100644 --- a/src/native/overlay/time_picker.rs +++ b/src/native/overlay/time_picker.rs @@ -460,13 +460,15 @@ where let mut keyboard_handle = |key_code: &keyboard::Key, time: &mut NaiveTime, duration: Duration| { match key_code { - keyboard::Key::Named(keyboard::key::Named::ArrowLeft) - | keyboard::Key::Named(keyboard::key::Named::ArrowDown) => { + keyboard::Key::Named( + keyboard::key::Named::ArrowLeft | keyboard::key::Named::ArrowDown, + ) => { *time -= duration; status = event::Status::Captured; } - keyboard::Key::Named(keyboard::key::Named::ArrowRight) - | keyboard::Key::Named(keyboard::key::Named::ArrowUp) => { + keyboard::Key::Named( + keyboard::key::Named::ArrowRight | keyboard::key::Named::ArrowUp, + ) => { *time += duration; status = event::Status::Captured; } @@ -589,7 +591,7 @@ where + 2.0 * SPACING, }); - let node = Node::with_children( + let mut node = Node::with_children( Size::new( clock.bounds().width + (2.0 * PADDING), clock.bounds().height @@ -601,7 +603,8 @@ where vec![clock, digital_clock, cancel_button, submit_button], ); - node.center_and_bounce(position, bounds) + node.center_and_bounce(position, bounds); + node } fn on_event(