From 2c782bbe7a048f6f091e15f68de29a846b9bb059 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 14 Sep 2023 19:35:29 +0200 Subject: Fix width of horizontal scrollbar in `Scrollable` --- widget/src/scrollable.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'widget') diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index def28821..7b1d7a30 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -1399,8 +1399,8 @@ impl Scrollbars { // Need to adjust the width of the horizontal scrollbar if the vertical scrollbar // is present - let scrollbar_y_width = show_scrollbar_y - .map_or(0.0, |v| v.width.max(v.scroller_width) + v.margin); + let scrollbar_y_width = y_scrollbar + .map_or(0.0, |scrollbar| scrollbar.total_bounds.width); let total_scrollbar_height = width.max(scroller_width) + 2.0 * margin; @@ -1425,12 +1425,12 @@ impl Scrollbars { let ratio = bounds.width / content_bounds.width; // min width for easier grabbing with extra wide content - let scroller_length = (bounds.width * ratio).max(2.0); - let scroller_offset = translation.x * ratio; + let scroller_length = (scrollbar_bounds.width * ratio).max(2.0); + let scroller_offset = + translation.x * ratio * scrollbar_bounds.width / bounds.width; let scroller_bounds = Rectangle { - x: (scrollbar_bounds.x + scroller_offset - scrollbar_y_width) - .max(0.0), + x: (scrollbar_bounds.x + scroller_offset).max(0.0), y: bounds.y + bounds.height - total_scrollbar_height / 2.0 - scroller_width / 2.0, -- cgit From ed11b04f6054809ea55ec9b3f0bd221ac2caf9ca Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 14 Sep 2023 22:59:02 +0200 Subject: Fix `height` of vertical scroller in `Scrollbar` --- widget/src/scrollable.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'widget') diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 7b1d7a30..f92e6223 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -1364,15 +1364,15 @@ impl Scrollbars { let ratio = bounds.height / content_bounds.height; // min height for easier grabbing with super tall content - let scroller_height = (bounds.height * ratio).max(2.0); - let scroller_offset = translation.y * ratio; + let scroller_height = (scrollbar_bounds.height * ratio).max(2.0); + let scroller_offset = + translation.y * ratio * scrollbar_bounds.height / bounds.height; let scroller_bounds = Rectangle { x: bounds.x + bounds.width - total_scrollbar_width / 2.0 - scroller_width / 2.0, - y: (scrollbar_bounds.y + scroller_offset - x_scrollbar_height) - .max(0.0), + y: (scrollbar_bounds.y + scroller_offset).max(0.0), width: scroller_width, height: scroller_height, }; -- cgit From 34f07b60273d6cfe13834af54cd0e24d34569387 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 04:11:52 +0200 Subject: Fix `clippy::semicolon_if_nothing_returned` --- widget/src/button.rs | 2 +- widget/src/column.rs | 2 +- widget/src/image.rs | 6 +++--- widget/src/image/viewer.rs | 2 +- widget/src/keyed/column.rs | 2 +- widget/src/lazy.rs | 6 +++--- widget/src/lazy/responsive.rs | 4 ++-- widget/src/pane_grid.rs | 4 ++-- widget/src/pane_grid/state.rs | 18 +++++++++--------- widget/src/pane_grid/title_bar.rs | 4 ++-- widget/src/pick_list.rs | 2 +- widget/src/row.rs | 4 ++-- widget/src/scrollable.rs | 10 +++++----- widget/src/slider.rs | 2 +- widget/src/text_input.rs | 24 ++++++++++++------------ widget/src/text_input/cursor.rs | 22 +++++++++++----------- widget/src/tooltip.rs | 2 +- widget/src/vertical_slider.rs | 2 +- 18 files changed, 59 insertions(+), 59 deletions(-) (limited to 'widget') diff --git a/widget/src/button.rs b/widget/src/button.rs index 4915bd49..384a3156 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -146,7 +146,7 @@ where } fn diff(&self, tree: &mut Tree) { - tree.diff_children(std::slice::from_ref(&self.content)) + tree.diff_children(std::slice::from_ref(&self.content)); } fn width(&self) -> Length { diff --git a/widget/src/column.rs b/widget/src/column.rs index f2347cc9..42e90ac1 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -159,7 +159,7 @@ where child .as_widget() .operate(state, layout, renderer, operation); - }) + }); }); } diff --git a/widget/src/image.rs b/widget/src/image.rs index 3c83c87b..a0e89920 100644 --- a/widget/src/image.rs +++ b/widget/src/image.rs @@ -141,14 +141,14 @@ pub fn draw( ..bounds }; - renderer.draw(handle.clone(), drawing_bounds + offset) + renderer.draw(handle.clone(), drawing_bounds + offset); }; if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height { renderer.with_layer(bounds, render); } else { - render(renderer) + render(renderer); } } @@ -191,7 +191,7 @@ where _cursor: mouse::Cursor, _viewport: &Rectangle, ) { - draw(renderer, layout, &self.handle, self.content_fit) + draw(renderer, layout, &self.handle, self.content_fit); } } diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs index 724d121e..44624fc8 100644 --- a/widget/src/image/viewer.rs +++ b/widget/src/image/viewer.rs @@ -334,7 +334,7 @@ where y: bounds.y, ..Rectangle::with_size(image_size) }, - ) + ); }); }); } diff --git a/widget/src/keyed/column.rs b/widget/src/keyed/column.rs index 19016679..0ef82407 100644 --- a/widget/src/keyed/column.rs +++ b/widget/src/keyed/column.rs @@ -220,7 +220,7 @@ where child .as_widget() .operate(state, layout, renderer, operation); - }) + }); }); } diff --git a/widget/src/lazy.rs b/widget/src/lazy.rs index bf695a57..589dd938 100644 --- a/widget/src/lazy.rs +++ b/widget/src/lazy.rs @@ -135,7 +135,7 @@ where (*self.element.borrow_mut()) = Some(current.element.clone()); self.with_element(|element| { - tree.diff_children(std::slice::from_ref(&element.as_widget())) + tree.diff_children(std::slice::from_ref(&element.as_widget())); }); } else { (*self.element.borrow_mut()) = Some(current.element.clone()); @@ -243,8 +243,8 @@ where layout, cursor, viewport, - ) - }) + ); + }); } fn overlay<'b>( diff --git a/widget/src/lazy/responsive.rs b/widget/src/lazy/responsive.rs index 0b819455..ed471988 100644 --- a/widget/src/lazy/responsive.rs +++ b/widget/src/lazy/responsive.rs @@ -240,9 +240,9 @@ where |tree, renderer, layout, element| { element.as_widget().draw( tree, renderer, theme, style, layout, cursor, viewport, - ) + ); }, - ) + ); } fn mouse_interaction( diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index f868a648..3fb25972 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -308,7 +308,7 @@ where .zip(layout.children()) .for_each(|(((_pane, content), state), layout)| { content.operate(state, layout, renderer, operation); - }) + }); }); } @@ -436,7 +436,7 @@ where tree, renderer, theme, style, layout, cursor, rectangle, ); }, - ) + ); } fn overlay<'b>( diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs index 28a52cf0..3721fa55 100644 --- a/widget/src/pane_grid/state.rs +++ b/widget/src/pane_grid/state.rs @@ -156,16 +156,16 @@ impl State { Region::Center => self.swap(pane, target), Region::Edge(edge) => match edge { Edge::Top => { - self.split_and_swap(Axis::Horizontal, target, pane, true) + self.split_and_swap(Axis::Horizontal, target, pane, true); } Edge::Bottom => { - self.split_and_swap(Axis::Horizontal, target, pane, false) + self.split_and_swap(Axis::Horizontal, target, pane, false); } Edge::Left => { - self.split_and_swap(Axis::Vertical, target, pane, true) + self.split_and_swap(Axis::Vertical, target, pane, true); } Edge::Right => { - self.split_and_swap(Axis::Vertical, target, pane, false) + self.split_and_swap(Axis::Vertical, target, pane, false); } }, } @@ -176,7 +176,7 @@ impl State { match target { Target::Edge(edge) => self.move_to_edge(pane, edge), Target::Pane(target, region) => { - self.split_with(&target, pane, region) + self.split_with(&target, pane, region); } } } @@ -241,16 +241,16 @@ impl State { pub fn move_to_edge(&mut self, pane: &Pane, edge: Edge) { match edge { Edge::Top => { - self.split_major_node_and_swap(Axis::Horizontal, pane, true) + self.split_major_node_and_swap(Axis::Horizontal, pane, true); } Edge::Bottom => { - self.split_major_node_and_swap(Axis::Horizontal, pane, false) + self.split_major_node_and_swap(Axis::Horizontal, pane, false); } Edge::Left => { - self.split_major_node_and_swap(Axis::Vertical, pane, true) + self.split_major_node_and_swap(Axis::Vertical, pane, true); } Edge::Right => { - self.split_major_node_and_swap(Axis::Vertical, pane, false) + self.split_major_node_and_swap(Axis::Vertical, pane, false); } } } diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs index 5ae7a6a0..f4dbb6b1 100644 --- a/widget/src/pane_grid/title_bar.rs +++ b/widget/src/pane_grid/title_bar.rs @@ -286,7 +286,7 @@ where controls_layout, renderer, operation, - ) + ); }; if show_title { @@ -295,7 +295,7 @@ where title_layout, renderer, operation, - ) + ); } } diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 056a5e65..fa0e3471 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -253,7 +253,7 @@ where &self.handle, &self.style, || tree.state.downcast_ref::>(), - ) + ); } fn overlay<'b>( diff --git a/widget/src/row.rs b/widget/src/row.rs index 71cf0509..7ca90fbb 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -101,7 +101,7 @@ where } fn diff(&self, tree: &mut Tree) { - tree.diff_children(&self.children) + tree.diff_children(&self.children); } fn width(&self) -> Length { @@ -148,7 +148,7 @@ where child .as_widget() .operate(state, layout, renderer, operation); - }) + }); }); } diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index f92e6223..6f1e68fc 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -217,7 +217,7 @@ where } fn diff(&self, tree: &mut Tree) { - tree.diff_children(std::slice::from_ref(&self.content)) + tree.diff_children(std::slice::from_ref(&self.content)); } fn width(&self) -> Length { @@ -348,9 +348,9 @@ where layout, cursor, viewport, - ) + ); }, - ) + ); } fn mouse_interaction( @@ -1069,7 +1069,7 @@ impl operation::Scrollable for State { } fn scroll_to(&mut self, offset: AbsoluteOffset) { - State::scroll_to(self, offset) + State::scroll_to(self, offset); } } @@ -1203,7 +1203,7 @@ impl State { (self.offset_y.absolute(bounds.height, content_bounds.height) - delta.y) .clamp(0.0, content_bounds.height - bounds.height), - ) + ); } if bounds.width < content_bounds.width { diff --git a/widget/src/slider.rs b/widget/src/slider.rs index 2c4a2913..ac0982c8 100644 --- a/widget/src/slider.rs +++ b/widget/src/slider.rs @@ -223,7 +223,7 @@ where &self.range, theme, &self.style, - ) + ); } fn mouse_interaction( diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 7d5ae806..9e1fb796 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -250,7 +250,7 @@ where self.is_secure, self.icon.as_ref(), &self.style, - ) + ); } } @@ -375,7 +375,7 @@ where self.is_secure, self.icon.as_ref(), &self.style, - ) + ); } fn mouse_interaction( @@ -622,7 +622,7 @@ where font, size, line_height, - ) + ); }; match event { @@ -849,7 +849,7 @@ where state.cursor.move_left_by_words(value); } } else if modifiers.shift() { - state.cursor.select_left(value) + state.cursor.select_left(value); } else { state.cursor.move_left(value); } @@ -864,7 +864,7 @@ where state.cursor.move_right_by_words(value); } } else if modifiers.shift() { - state.cursor.select_right(value) + state.cursor.select_right(value); } else { state.cursor.move_right(value); } @@ -1220,7 +1220,7 @@ pub fn draw( if text_width > text_bounds.width { renderer.with_layer(text_bounds, |renderer| { - renderer.with_translation(Vector::new(-offset, 0.0), render) + renderer.with_translation(Vector::new(-offset, 0.0), render); }); } else { render(renderer); @@ -1342,29 +1342,29 @@ impl operation::Focusable for State

{ } fn focus(&mut self) { - State::focus(self) + State::focus(self); } fn unfocus(&mut self) { - State::unfocus(self) + State::unfocus(self); } } impl operation::TextInput for State

{ fn move_cursor_to_front(&mut self) { - State::move_cursor_to_front(self) + State::move_cursor_to_front(self); } fn move_cursor_to_end(&mut self) { - State::move_cursor_to_end(self) + State::move_cursor_to_end(self); } fn move_cursor_to(&mut self, position: usize) { - State::move_cursor_to(self, position) + State::move_cursor_to(self, position); } fn select_all(&mut self) { - State::select_all(self) + State::select_all(self); } } diff --git a/widget/src/text_input/cursor.rs b/widget/src/text_input/cursor.rs index 9680dfd7..ea902485 100644 --- a/widget/src/text_input/cursor.rs +++ b/widget/src/text_input/cursor.rs @@ -65,11 +65,11 @@ impl Cursor { } pub(crate) fn move_right(&mut self, value: &Value) { - self.move_right_by_amount(value, 1) + self.move_right_by_amount(value, 1); } pub(crate) fn move_right_by_words(&mut self, value: &Value) { - self.move_to(value.next_end_of_word(self.right(value))) + self.move_to(value.next_end_of_word(self.right(value))); } pub(crate) fn move_right_by_amount( @@ -79,7 +79,7 @@ impl Cursor { ) { match self.state(value) { State::Index(index) => { - self.move_to(index.saturating_add(amount).min(value.len())) + self.move_to(index.saturating_add(amount).min(value.len())); } State::Selection { start, end } => self.move_to(end.max(start)), } @@ -108,10 +108,10 @@ impl Cursor { pub(crate) fn select_left(&mut self, value: &Value) { match self.state(value) { State::Index(index) if index > 0 => { - self.select_range(index, index - 1) + self.select_range(index, index - 1); } State::Selection { start, end } if end > 0 => { - self.select_range(start, end - 1) + self.select_range(start, end - 1); } _ => {} } @@ -120,10 +120,10 @@ impl Cursor { pub(crate) fn select_right(&mut self, value: &Value) { match self.state(value) { State::Index(index) if index < value.len() => { - self.select_range(index, index + 1) + self.select_range(index, index + 1); } State::Selection { start, end } if end < value.len() => { - self.select_range(start, end + 1) + self.select_range(start, end + 1); } _ => {} } @@ -132,10 +132,10 @@ impl Cursor { pub(crate) fn select_left_by_words(&mut self, value: &Value) { match self.state(value) { State::Index(index) => { - self.select_range(index, value.previous_start_of_word(index)) + self.select_range(index, value.previous_start_of_word(index)); } State::Selection { start, end } => { - self.select_range(start, value.previous_start_of_word(end)) + self.select_range(start, value.previous_start_of_word(end)); } } } @@ -143,10 +143,10 @@ impl Cursor { pub(crate) fn select_right_by_words(&mut self, value: &Value) { match self.state(value) { State::Index(index) => { - self.select_range(index, value.next_end_of_word(index)) + self.select_range(index, value.next_end_of_word(index)); } State::Selection { start, end } => { - self.select_range(start, value.next_end_of_word(end)) + self.select_range(start, value.next_end_of_word(end)); } } } diff --git a/widget/src/tooltip.rs b/widget/src/tooltip.rs index edc74e31..b041d2e9 100644 --- a/widget/src/tooltip.rs +++ b/widget/src/tooltip.rs @@ -114,7 +114,7 @@ where } fn diff(&self, tree: &mut widget::Tree) { - tree.diff_children(&[self.content.as_widget(), &self.tooltip]) + tree.diff_children(&[self.content.as_widget(), &self.tooltip]); } fn state(&self) -> widget::tree::State { diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs index 1efcd63b..01d3359c 100644 --- a/widget/src/vertical_slider.rs +++ b/widget/src/vertical_slider.rs @@ -220,7 +220,7 @@ where &self.range, theme, &self.style, - ) + ); } fn mouse_interaction( -- cgit From 6c386e90a12fd26da12541da3f086dddb7211c0c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 04:33:48 +0200 Subject: Fix `clippy::trivially-copy-pass-by-ref` --- widget/src/pane_grid/node.rs | 14 +++++------ widget/src/pane_grid/state.rs | 54 +++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 34 deletions(-) (limited to 'widget') diff --git a/widget/src/pane_grid/node.rs b/widget/src/pane_grid/node.rs index 3c707f15..1f568f95 100644 --- a/widget/src/pane_grid/node.rs +++ b/widget/src/pane_grid/node.rs @@ -95,13 +95,13 @@ impl Node { splits } - pub(crate) fn find(&mut self, pane: &Pane) -> Option<&mut Node> { + pub(crate) fn find(&mut self, pane: Pane) -> Option<&mut Node> { match self { Node::Split { a, b, .. } => { a.find(pane).or_else(move || b.find(pane)) } Node::Pane(p) => { - if p == pane { + if *p == pane { Some(self) } else { None @@ -139,12 +139,12 @@ impl Node { f(self); } - pub(crate) fn resize(&mut self, split: &Split, percentage: f32) -> bool { + pub(crate) fn resize(&mut self, split: Split, percentage: f32) -> bool { match self { Node::Split { id, ratio, a, b, .. } => { - if id == split { + if *id == split { *ratio = percentage; true @@ -158,13 +158,13 @@ impl Node { } } - pub(crate) fn remove(&mut self, pane: &Pane) -> Option { + pub(crate) fn remove(&mut self, pane: Pane) -> Option { match self { Node::Split { a, b, .. } => { - if a.pane() == Some(*pane) { + if a.pane() == Some(pane) { *self = *b.clone(); Some(self.first_pane()) - } else if b.pane() == Some(*pane) { + } else if b.pane() == Some(pane) { *self = *a.clone(); Some(self.first_pane()) } else { diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs index 3721fa55..481cd770 100644 --- a/widget/src/pane_grid/state.rs +++ b/widget/src/pane_grid/state.rs @@ -75,14 +75,14 @@ impl State { } /// Returns the internal state of the given [`Pane`], if it exists. - pub fn get(&self, pane: &Pane) -> Option<&T> { - self.panes.get(pane) + pub fn get(&self, pane: Pane) -> Option<&T> { + self.panes.get(&pane) } /// Returns the internal state of the given [`Pane`] with mutability, if it /// exists. - pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> { - self.panes.get_mut(pane) + pub fn get_mut(&mut self, pane: Pane) -> Option<&mut T> { + self.panes.get_mut(&pane) } /// Returns an iterator over all the panes of the [`State`], alongside its @@ -104,13 +104,13 @@ impl State { /// Returns the adjacent [`Pane`] of another [`Pane`] in the given /// direction, if there is one. - pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option { + pub fn adjacent(&self, pane: Pane, direction: Direction) -> Option { let regions = self .internal .layout .pane_regions(0.0, Size::new(4096.0, 4096.0)); - let current_region = regions.get(pane)?; + let current_region = regions.get(&pane)?; let target = match direction { Direction::Left => { @@ -142,7 +142,7 @@ impl State { pub fn split( &mut self, axis: Axis, - pane: &Pane, + pane: Pane, state: T, ) -> Option<(Pane, Split)> { self.split_node(axis, Some(pane), state, false) @@ -151,7 +151,7 @@ impl State { /// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`]. /// /// Panes will be swapped by default for [`Region::Center`]. - pub fn split_with(&mut self, target: &Pane, pane: &Pane, region: Region) { + pub fn split_with(&mut self, target: Pane, pane: Pane, region: Region) { match region { Region::Center => self.swap(pane, target), Region::Edge(edge) => match edge { @@ -172,11 +172,11 @@ impl State { } /// Drops the given [`Pane`] into the provided [`Target`]. - pub fn drop(&mut self, pane: &Pane, target: Target) { + pub fn drop(&mut self, pane: Pane, target: Target) { match target { Target::Edge(edge) => self.move_to_edge(pane, edge), Target::Pane(target, region) => { - self.split_with(&target, pane, region); + self.split_with(target, pane, region); } } } @@ -184,7 +184,7 @@ impl State { fn split_node( &mut self, axis: Axis, - pane: Option<&Pane>, + pane: Option, state: T, inverse: bool, ) -> Option<(Pane, Split)> { @@ -222,14 +222,14 @@ impl State { fn split_and_swap( &mut self, axis: Axis, - target: &Pane, - pane: &Pane, + target: Pane, + pane: Pane, swap: bool, ) { if let Some((state, _)) = self.close(pane) { if let Some((new_pane, _)) = self.split(axis, target, state) { if swap { - self.swap(target, &new_pane); + self.swap(target, new_pane); } } } @@ -238,7 +238,7 @@ impl State { /// Move [`Pane`] to an [`Edge`] of the [`PaneGrid`]. /// /// [`PaneGrid`]: super::PaneGrid - pub fn move_to_edge(&mut self, pane: &Pane, edge: Edge) { + pub fn move_to_edge(&mut self, pane: Pane, edge: Edge) { match edge { Edge::Top => { self.split_major_node_and_swap(Axis::Horizontal, pane, true); @@ -258,7 +258,7 @@ impl State { fn split_major_node_and_swap( &mut self, axis: Axis, - pane: &Pane, + pane: Pane, swap: bool, ) { if let Some((state, _)) = self.close(pane) { @@ -273,14 +273,14 @@ impl State { /// /// [`PaneGrid`]: super::PaneGrid /// [`DragEvent`]: super::DragEvent - pub fn swap(&mut self, a: &Pane, b: &Pane) { + pub fn swap(&mut self, a: Pane, b: Pane) { self.internal.layout.update(&|node| match node { Node::Split { .. } => {} Node::Pane(pane) => { - if pane == a { - *node = Node::Pane(*b); - } else if pane == b { - *node = Node::Pane(*a); + if *pane == a { + *node = Node::Pane(b); + } else if *pane == b { + *node = Node::Pane(a); } } }); @@ -296,19 +296,19 @@ impl State { /// /// [`PaneGrid`]: super::PaneGrid /// [`ResizeEvent`]: super::ResizeEvent - pub fn resize(&mut self, split: &Split, ratio: f32) { + pub fn resize(&mut self, split: Split, ratio: f32) { let _ = self.internal.layout.resize(split, ratio); } /// Closes the given [`Pane`] and returns its internal state and its closest /// sibling, if it exists. - pub fn close(&mut self, pane: &Pane) -> Option<(T, Pane)> { - if self.maximized == Some(*pane) { + pub fn close(&mut self, pane: Pane) -> Option<(T, Pane)> { + if self.maximized == Some(pane) { let _ = self.maximized.take(); } if let Some(sibling) = self.internal.layout.remove(pane) { - self.panes.remove(pane).map(|state| (state, sibling)) + self.panes.remove(&pane).map(|state| (state, sibling)) } else { None } @@ -318,8 +318,8 @@ impl State { /// [`PaneGrid`] until [`Self::restore()`] is called. /// /// [`PaneGrid`]: super::PaneGrid - pub fn maximize(&mut self, pane: &Pane) { - self.maximized = Some(*pane); + pub fn maximize(&mut self, pane: Pane) { + self.maximized = Some(pane); } /// Restore the currently maximized [`Pane`] to it's normal size. All panes -- cgit From 42ed90bc6f92b2085d193e7f143430b8d3847c21 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 04:51:08 +0200 Subject: Fix `clippy::default_trait_access` --- widget/src/pick_list.rs | 2 +- widget/src/scrollable.rs | 2 +- widget/src/toggler.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'widget') diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index fa0e3471..27f32907 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -76,7 +76,7 @@ where text_line_height: text::LineHeight::default(), text_shaping: text::Shaping::Basic, font: None, - handle: Default::default(), + handle: Handle::default(), style: Default::default(), } } diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 6f1e68fc..4cc97684 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -46,7 +46,7 @@ where id: None, width: Length::Shrink, height: Length::Shrink, - direction: Default::default(), + direction: Direction::default(), content: content.into(), on_scroll: None, style: Default::default(), diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index 2440317f..476c8330 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -286,7 +286,7 @@ where style, label_layout, tree.state.downcast_ref(), - Default::default(), + crate::text::Appearance::default(), ); } -- cgit From caed50b277495e4375975f3f4e271b8fcbc0c33f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 05:03:25 +0200 Subject: Fix `clippy::match-wildcard-for-single-variants` --- widget/src/scrollable.rs | 4 ++-- widget/src/text_input/cursor.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'widget') diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 4cc97684..49aed2f0 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -117,7 +117,7 @@ impl Direction { match self { Self::Horizontal(properties) => Some(properties), Self::Both { horizontal, .. } => Some(horizontal), - _ => None, + Self::Vertical(_) => None, } } @@ -126,7 +126,7 @@ impl Direction { match self { Self::Vertical(properties) => Some(properties), Self::Both { vertical, .. } => Some(vertical), - _ => None, + Self::Horizontal(_) => None, } } } diff --git a/widget/src/text_input/cursor.rs b/widget/src/text_input/cursor.rs index ea902485..f682b17d 100644 --- a/widget/src/text_input/cursor.rs +++ b/widget/src/text_input/cursor.rs @@ -56,7 +56,7 @@ impl Cursor { State::Selection { start, end } => { Some((start.min(end), start.max(end))) } - _ => None, + State::Index(_) => None, } } @@ -89,7 +89,7 @@ impl Cursor { match self.state(value) { State::Index(index) if index > 0 => self.move_to(index - 1), State::Selection { start, end } => self.move_to(start.min(end)), - _ => self.move_to(0), + State::Index(_) => self.move_to(0), } } -- cgit From 1e4bade53aaaeb17542d0372ac827bcb7daf037c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 05:07:34 +0200 Subject: Fix `clippy::redundant-closure-for-method-calls` --- widget/src/lazy/component.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'widget') diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index fe99a7f2..d454b72b 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -511,7 +511,7 @@ impl<'a, 'b, Message, Renderer, Event, S> Drop for Overlay<'a, 'b, Message, Renderer, Event, S> { fn drop(&mut self) { - if let Some(heads) = self.0.take().map(|inner| inner.into_heads()) { + if let Some(heads) = self.0.take().map(Inner::into_heads) { *heads.instance.tree.borrow_mut().borrow_mut() = Some(heads.tree); } } -- cgit From 1019d1e518d8ffe760142ccd5ff33d077434c8b9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 05:23:15 +0200 Subject: Fix `clippy::filter_map_next` --- widget/src/pane_grid.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'widget') diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index 3fb25972..2d25a543 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -606,11 +606,10 @@ pub fn update<'a, Message, T: Draggable>( } else { let dropped_region = contents .zip(layout.children()) - .filter_map(|(target, layout)| { + .find_map(|(target, layout)| { layout_region(layout, cursor_position) .map(|region| (target, region)) - }) - .next(); + }); match dropped_region { Some(((target, _), region)) @@ -1151,21 +1150,19 @@ pub struct ResizeEvent { * Helpers */ fn hovered_split<'a>( - splits: impl Iterator, + mut splits: impl Iterator, spacing: f32, cursor_position: Point, ) -> Option<(Split, Axis, Rectangle)> { - splits - .filter_map(|(split, (axis, region, ratio))| { - let bounds = axis.split_line_bounds(*region, *ratio, spacing); + splits.find_map(|(split, (axis, region, ratio))| { + let bounds = axis.split_line_bounds(*region, *ratio, spacing); - if bounds.contains(cursor_position) { - Some((*split, *axis, bounds)) - } else { - None - } - }) - .next() + if bounds.contains(cursor_position) { + Some((*split, *axis, bounds)) + } else { + None + } + }) } /// The visible contents of the [`PaneGrid`] -- cgit From f137d71e8fb926e784680d56d1cfa6817c3710a1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 16:40:03 +0200 Subject: Centralize `clippy` lints in `.cargo/config.toml` --- widget/src/lib.rs | 6 ------ widget/src/text_input/value.rs | 11 ++++++----- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'widget') diff --git a/widget/src/lib.rs b/widget/src/lib.rs index 7e204171..6feb948c 100644 --- a/widget/src/lib.rs +++ b/widget/src/lib.rs @@ -7,14 +7,8 @@ missing_debug_implementations, missing_docs, unused_results, - clippy::extra_unused_lifetimes, - clippy::from_over_into, - clippy::needless_borrow, - clippy::new_without_default, - clippy::useless_conversion, rustdoc::broken_intra_doc_links )] -#![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] pub use iced_renderer as renderer; pub use iced_renderer::graphics; diff --git a/widget/src/text_input/value.rs b/widget/src/text_input/value.rs index d1b056c8..46a1f754 100644 --- a/widget/src/text_input/value.rs +++ b/widget/src/text_input/value.rs @@ -89,11 +89,6 @@ impl Value { Self { graphemes } } - /// Converts the [`Value`] into a `String`. - pub fn to_string(&self) -> String { - self.graphemes.concat() - } - /// Inserts a new `char` at the given grapheme `index`. pub fn insert(&mut self, index: usize, c: char) { self.graphemes.insert(index, c.to_string()); @@ -131,3 +126,9 @@ impl Value { } } } + +impl std::fmt::Display for Value { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.graphemes.concat()) + } +} -- cgit