diff options
author | 2023-06-08 20:16:46 +0200 | |
---|---|---|
committer | 2023-06-08 20:16:46 +0200 | |
commit | 5c8cfb411ed0a9a6e55bd1193cd7e97252e63d28 (patch) | |
tree | b4f6ae33729d3ddc0d8c529a54f401fec305f00a | |
parent | 34451bff185d8875f55747ee97ed746828e30f40 (diff) | |
download | iced-5c8cfb411ed0a9a6e55bd1193cd7e97252e63d28.tar.gz iced-5c8cfb411ed0a9a6e55bd1193cd7e97252e63d28.tar.bz2 iced-5c8cfb411ed0a9a6e55bd1193cd7e97252e63d28.zip |
Take `Rectangle` by value in `Cursor` API
-rw-r--r-- | core/src/mouse/cursor.rs | 6 | ||||
-rw-r--r-- | examples/bezier_tool/src/main.rs | 6 | ||||
-rw-r--r-- | examples/game_of_life/src/main.rs | 11 | ||||
-rw-r--r-- | examples/geometry/src/main.rs | 2 | ||||
-rw-r--r-- | examples/modal/src/main.rs | 2 | ||||
-rw-r--r-- | examples/sierpinski_triangle/src/main.rs | 12 | ||||
-rw-r--r-- | widget/src/button.rs | 8 | ||||
-rw-r--r-- | widget/src/checkbox.rs | 6 | ||||
-rw-r--r-- | widget/src/image/viewer.rs | 2 | ||||
-rw-r--r-- | widget/src/mouse_area.rs | 2 | ||||
-rw-r--r-- | widget/src/overlay/menu.rs | 10 | ||||
-rw-r--r-- | widget/src/pane_grid.rs | 2 | ||||
-rw-r--r-- | widget/src/pane_grid/content.rs | 2 | ||||
-rw-r--r-- | widget/src/pick_list.rs | 8 | ||||
-rw-r--r-- | widget/src/radio.rs | 6 | ||||
-rw-r--r-- | widget/src/scrollable.rs | 6 | ||||
-rw-r--r-- | widget/src/slider.rs | 7 | ||||
-rw-r--r-- | widget/src/text_input.rs | 6 | ||||
-rw-r--r-- | widget/src/toggler.rs | 6 | ||||
-rw-r--r-- | widget/src/tooltip.rs | 2 | ||||
-rw-r--r-- | widget/src/vertical_slider.rs | 7 |
21 files changed, 57 insertions, 62 deletions
diff --git a/core/src/mouse/cursor.rs b/core/src/mouse/cursor.rs index d4cb415d..223ed96d 100644 --- a/core/src/mouse/cursor.rs +++ b/core/src/mouse/cursor.rs @@ -24,7 +24,7 @@ impl Cursor { /// /// If the [`Cursor`] is not over the provided bounds, this method will /// return `None`. - pub fn position_over(self, bounds: &Rectangle) -> Option<Point> { + pub fn position_over(self, bounds: Rectangle) -> Option<Point> { self.position().filter(|p| bounds.contains(*p)) } @@ -33,7 +33,7 @@ impl Cursor { /// /// If the [`Cursor`] is not over the provided bounds, this method will /// return `None`. - pub fn position_in(self, bounds: &Rectangle) -> Option<Point> { + pub fn position_in(self, bounds: Rectangle) -> Option<Point> { self.position_over(bounds) .map(|p| p - Vector::new(bounds.x, bounds.y)) } @@ -45,7 +45,7 @@ impl Cursor { } /// Returns true if the [`Cursor`] is over the given `bounds`. - pub fn is_over(self, bounds: &Rectangle) -> bool { + pub fn is_over(self, bounds: Rectangle) -> bool { self.position_over(bounds).is_some() } } diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index b4568cbf..310be28f 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -101,7 +101,7 @@ mod bezier { cursor: mouse::Cursor, ) -> (event::Status, Option<Curve>) { let cursor_position = - if let Some(position) = cursor.position_in(&bounds) { + if let Some(position) = cursor.position_in(bounds) { position } else { return (event::Status::Ignored, None); @@ -183,7 +183,7 @@ mod bezier { bounds: Rectangle, cursor: mouse::Cursor, ) -> mouse::Interaction { - if cursor.is_over(&bounds) { + if cursor.is_over(bounds) { mouse::Interaction::Crosshair } else { mouse::Interaction::default() @@ -226,7 +226,7 @@ mod bezier { ) -> Geometry { let mut frame = Frame::new(renderer, bounds.size()); - if let Some(cursor_position) = cursor.position_in(&bounds) { + if let Some(cursor_position) = cursor.position_in(bounds) { match *self { Pending::One { from } => { let line = Path::line(from, cursor_position); diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index aaa8efd1..e951d734 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -407,7 +407,7 @@ mod grid { } let cursor_position = - if let Some(position) = cursor.position_in(&bounds) { + if let Some(position) = cursor.position_in(bounds) { position } else { return (event::Status::Ignored, None); @@ -567,10 +567,9 @@ mod grid { let overlay = { let mut frame = Frame::new(renderer, bounds.size()); - let hovered_cell = - cursor.position_in(&bounds).map(|position| { - Cell::at(self.project(position, frame.size())) - }); + let hovered_cell = cursor.position_in(bounds).map(|position| { + Cell::at(self.project(position, frame.size())) + }); if let Some(cell) = hovered_cell { frame.with_save(|frame| { @@ -675,7 +674,7 @@ mod grid { Interaction::Drawing => mouse::Interaction::Crosshair, Interaction::Erasing => mouse::Interaction::Crosshair, Interaction::Panning { .. } => mouse::Interaction::Grabbing, - Interaction::None if cursor.is_over(&bounds) => { + Interaction::None if cursor.is_over(bounds) => { mouse::Interaction::Crosshair } _ => mouse::Interaction::default(), diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index 1f949d10..29f78ea1 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -62,7 +62,7 @@ mod rainbow { let color_v = [0.75, 0.0, 0.5, 1.0]; let posn_center = { - if let Some(cursor_position) = cursor.position_in(&bounds) { + if let Some(cursor_position) = cursor.position_in(bounds) { [cursor_position.x, cursor_position.y] } else { [bounds.width / 2.0, bounds.height / 2.0] diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs index 82ed05d2..5c43c203 100644 --- a/examples/modal/src/main.rs +++ b/examples/modal/src/main.rs @@ -390,7 +390,7 @@ mod modal { mouse::Button::Left, )) = &event { - if !cursor.is_over(&content_bounds) { + if !cursor.is_over(content_bounds) { shell.publish(message.clone()); return event::Status::Captured; } diff --git a/examples/sierpinski_triangle/src/main.rs b/examples/sierpinski_triangle/src/main.rs index ad681a91..885d3c63 100644 --- a/examples/sierpinski_triangle/src/main.rs +++ b/examples/sierpinski_triangle/src/main.rs @@ -108,12 +108,12 @@ impl canvas::Program<Message> for SierpinskiGraph { bounds: Rectangle, cursor: mouse::Cursor, ) -> (event::Status, Option<Message>) { - let cursor_position = - if let Some(position) = cursor.position_in(&bounds) { - position - } else { - return (event::Status::Ignored, None); - }; + let cursor_position = if let Some(position) = cursor.position_in(bounds) + { + position + } else { + return (event::Status::Ignored, None); + }; match event { Event::Mouse(mouse_event) => { diff --git a/widget/src/button.rs b/widget/src/button.rs index 89af341c..0f3cbde2 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -311,7 +311,7 @@ pub fn update<'a, Message: Clone>( if on_press.is_some() { let bounds = layout.bounds(); - if cursor.is_over(&bounds) { + if cursor.is_over(bounds) { let state = state(); state.is_pressed = true; @@ -330,7 +330,7 @@ pub fn update<'a, Message: Clone>( let bounds = layout.bounds(); - if cursor.is_over(&bounds) { + if cursor.is_over(bounds) { shell.publish(on_press); } @@ -364,7 +364,7 @@ pub fn draw<'a, Renderer: crate::core::Renderer>( where Renderer::Theme: StyleSheet, { - let is_mouse_over = cursor.is_over(&bounds); + let is_mouse_over = cursor.is_over(bounds); let styling = if !is_enabled { style_sheet.disabled(style) @@ -440,7 +440,7 @@ pub fn mouse_interaction( cursor: mouse::Cursor, is_enabled: bool, ) -> mouse::Interaction { - let is_mouse_over = cursor.is_over(&layout.bounds()); + let is_mouse_over = cursor.is_over(layout.bounds()); if is_mouse_over && is_enabled { mouse::Interaction::Pointer diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs index 86f573dd..aa0bff42 100644 --- a/widget/src/checkbox.rs +++ b/widget/src/checkbox.rs @@ -212,7 +212,7 @@ where match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) | Event::Touch(touch::Event::FingerPressed { .. }) => { - let mouse_over = cursor.is_over(&layout.bounds()); + let mouse_over = cursor.is_over(layout.bounds()); if mouse_over { shell.publish((self.on_toggle)(!self.is_checked)); @@ -234,7 +234,7 @@ where _viewport: &Rectangle, _renderer: &Renderer, ) -> mouse::Interaction { - if cursor.is_over(&layout.bounds()) { + if cursor.is_over(layout.bounds()) { mouse::Interaction::Pointer } else { mouse::Interaction::default() @@ -251,7 +251,7 @@ where cursor: mouse::Cursor, _viewport: &Rectangle, ) { - let is_mouse_over = cursor.is_over(&layout.bounds()); + let is_mouse_over = cursor.is_over(layout.bounds()); let mut children = layout.children(); diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs index a2ee1e5c..8040d6bd 100644 --- a/widget/src/image/viewer.rs +++ b/widget/src/image/viewer.rs @@ -286,7 +286,7 @@ where ) -> mouse::Interaction { let state = tree.state.downcast_ref::<State>(); let bounds = layout.bounds(); - let is_mouse_over = cursor.is_over(&bounds); + let is_mouse_over = cursor.is_over(bounds); if state.is_cursor_grabbed() { mouse::Interaction::Grabbing diff --git a/widget/src/mouse_area.rs b/widget/src/mouse_area.rs index 423f070c..da7dc88f 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -240,7 +240,7 @@ fn update<Message: Clone, Renderer>( cursor: mouse::Cursor, shell: &mut Shell<'_, Message>, ) -> event::Status { - if !cursor.is_over(&layout.bounds()) { + if !cursor.is_over(layout.bounds()) { return event::Status::Ignored; } diff --git a/widget/src/overlay/menu.rs b/widget/src/overlay/menu.rs index fe1175ac..b699def0 100644 --- a/widget/src/overlay/menu.rs +++ b/widget/src/overlay/menu.rs @@ -376,9 +376,7 @@ where ) -> event::Status { match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { - let bounds = layout.bounds(); - - if cursor.is_over(&bounds) { + if cursor.is_over(layout.bounds()) { if let Some(index) = *self.hovered_option { if let Some(option) = self.options.get(index) { *self.last_selection = Some(option.clone()); @@ -388,7 +386,7 @@ where } Event::Mouse(mouse::Event::CursorMoved { .. }) => { if let Some(cursor_position) = - cursor.position_in(&layout.bounds()) + cursor.position_in(layout.bounds()) { let text_size = self .text_size @@ -404,7 +402,7 @@ where } Event::Touch(touch::Event::FingerPressed { .. }) => { if let Some(cursor_position) = - cursor.position_in(&layout.bounds()) + cursor.position_in(layout.bounds()) { let text_size = self .text_size @@ -438,7 +436,7 @@ where _viewport: &Rectangle, _renderer: &Renderer, ) -> mouse::Interaction { - let is_mouse_over = cursor.is_over(&layout.bounds()); + let is_mouse_over = cursor.is_over(layout.bounds()); if is_mouse_over { mouse::Interaction::Pointer diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index 7e0198fe..040d6bb3 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -524,7 +524,7 @@ pub fn update<'a, Message, T: Draggable>( | Event::Touch(touch::Event::FingerPressed { .. }) => { let bounds = layout.bounds(); - if let Some(cursor_position) = cursor.position_over(&bounds) { + if let Some(cursor_position) = cursor.position_over(bounds) { event_status = event::Status::Captured; match on_resize { diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs index fe5c6af0..c28ae6e3 100644 --- a/widget/src/pane_grid/content.rs +++ b/widget/src/pane_grid/content.rs @@ -113,7 +113,7 @@ where let title_bar_layout = children.next().unwrap(); let body_layout = children.next().unwrap(); - let show_controls = cursor.is_over(&bounds); + let show_controls = cursor.is_over(bounds); self.body.as_widget().draw( &tree.children[0], diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index d1c03bcd..dc53a9c8 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -452,7 +452,7 @@ where state.is_open = false; event::Status::Captured - } else if cursor.is_over(&layout.bounds()) { + } else if cursor.is_over(layout.bounds()) { state.is_open = true; state.hovered_option = options.iter().position(|option| Some(option) == selected); @@ -478,7 +478,7 @@ where let state = state(); if state.keyboard_modifiers.command() - && cursor.is_over(&layout.bounds()) + && cursor.is_over(layout.bounds()) && !state.is_open { fn find_next<'a, T: PartialEq>( @@ -532,7 +532,7 @@ pub fn mouse_interaction( cursor: mouse::Cursor, ) -> mouse::Interaction { let bounds = layout.bounds(); - let is_mouse_over = cursor.is_over(&bounds); + let is_mouse_over = cursor.is_over(bounds); if is_mouse_over { mouse::Interaction::Pointer @@ -610,7 +610,7 @@ pub fn draw<'a, T, Renderer>( T: ToString + 'a, { let bounds = layout.bounds(); - let is_mouse_over = cursor.is_over(&bounds); + let is_mouse_over = cursor.is_over(bounds); let is_selected = selected.is_some(); let style = if is_mouse_over { diff --git a/widget/src/radio.rs b/widget/src/radio.rs index 9c954275..5b883147 100644 --- a/widget/src/radio.rs +++ b/widget/src/radio.rs @@ -237,7 +237,7 @@ where match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) | Event::Touch(touch::Event::FingerPressed { .. }) => { - if cursor.is_over(&layout.bounds()) { + if cursor.is_over(layout.bounds()) { shell.publish(self.on_click.clone()); return event::Status::Captured; @@ -257,7 +257,7 @@ where _viewport: &Rectangle, _renderer: &Renderer, ) -> mouse::Interaction { - if cursor.is_over(&layout.bounds()) { + if cursor.is_over(layout.bounds()) { mouse::Interaction::Pointer } else { mouse::Interaction::default() @@ -274,7 +274,7 @@ where cursor: mouse::Cursor, _viewport: &Rectangle, ) { - let is_mouse_over = cursor.is_over(&layout.bounds()); + let is_mouse_over = cursor.is_over(layout.bounds()); let mut children = layout.children(); diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index e5cda4df..d90aca2b 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -443,7 +443,7 @@ pub fn update<Message>( ) -> event::Status, ) -> event::Status { let bounds = layout.bounds(); - let cursor_over_scrollable = cursor.position_over(&bounds); + let cursor_over_scrollable = cursor.position_over(bounds); let content = layout.children().next().unwrap(); let content_bounds = content.bounds(); @@ -698,7 +698,7 @@ pub fn mouse_interaction( ) -> mouse::Interaction, ) -> mouse::Interaction { let bounds = layout.bounds(); - let cursor_over_scrollable = cursor.position_over(&bounds); + let cursor_over_scrollable = cursor.position_over(bounds); let content_layout = layout.children().next().unwrap(); let content_bounds = content_layout.bounds(); @@ -759,7 +759,7 @@ pub fn draw<Renderer>( let scrollbars = Scrollbars::new(state, vertical, horizontal, bounds, content_bounds); - let cursor_over_scrollable = cursor.position_over(&bounds); + let cursor_over_scrollable = cursor.position_over(bounds); let (mouse_over_y_scrollbar, mouse_over_x_scrollbar) = scrollbars.is_mouse_over(cursor); diff --git a/widget/src/slider.rs b/widget/src/slider.rs index 4f35805c..3ea4391b 100644 --- a/widget/src/slider.rs +++ b/widget/src/slider.rs @@ -305,8 +305,7 @@ where match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) | Event::Touch(touch::Event::FingerPressed { .. }) => { - if let Some(cursor_position) = - cursor.position_over(&layout.bounds()) + if let Some(cursor_position) = cursor.position_over(layout.bounds()) { change(cursor_position); state.is_dragging = true; @@ -356,7 +355,7 @@ pub fn draw<T, R>( R::Theme: StyleSheet, { let bounds = layout.bounds(); - let is_mouse_over = cursor.is_over(&bounds); + let is_mouse_over = cursor.is_over(bounds); let style = if state.is_dragging { style_sheet.dragging(style) @@ -446,7 +445,7 @@ pub fn mouse_interaction( state: &State, ) -> mouse::Interaction { let bounds = layout.bounds(); - let is_mouse_over = cursor.is_over(&bounds); + let is_mouse_over = cursor.is_over(bounds); if state.is_dragging { mouse::Interaction::Grabbing diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 5b3705d4..272263f9 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -552,7 +552,7 @@ where let state = state(); let click_position = if on_input.is_some() { - cursor.position_over(&layout.bounds()) + cursor.position_over(layout.bounds()) } else { None }; @@ -971,7 +971,7 @@ pub fn draw<Renderer>( let mut children_layout = layout.children(); let text_bounds = children_layout.next().unwrap().bounds(); - let is_mouse_over = cursor.is_over(&bounds); + let is_mouse_over = cursor.is_over(bounds); let appearance = if is_disabled { theme.disabled(style) @@ -1161,7 +1161,7 @@ pub fn mouse_interaction( cursor: mouse::Cursor, is_disabled: bool, ) -> mouse::Interaction { - if cursor.is_over(&layout.bounds()) { + if cursor.is_over(layout.bounds()) { if is_disabled { mouse::Interaction::NotAllowed } else { diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index 28715c5a..8b51f2d0 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -209,7 +209,7 @@ where ) -> event::Status { match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { - let mouse_over = cursor.is_over(&layout.bounds()); + let mouse_over = cursor.is_over(layout.bounds()); if mouse_over { shell.publish((self.on_toggle)(!self.is_toggled)); @@ -231,7 +231,7 @@ where _viewport: &Rectangle, _renderer: &Renderer, ) -> mouse::Interaction { - if cursor.is_over(&layout.bounds()) { + if cursor.is_over(layout.bounds()) { mouse::Interaction::Pointer } else { mouse::Interaction::default() @@ -278,7 +278,7 @@ where let toggler_layout = children.next().unwrap(); let bounds = toggler_layout.bounds(); - let is_mouse_over = cursor.is_over(&layout.bounds()); + let is_mouse_over = cursor.is_over(layout.bounds()); let style = if is_mouse_over { theme.hovered(&self.style, self.is_toggled) diff --git a/widget/src/tooltip.rs b/widget/src/tooltip.rs index 024cfa9c..d425de01 100644 --- a/widget/src/tooltip.rs +++ b/widget/src/tooltip.rs @@ -287,7 +287,7 @@ pub fn draw<Renderer>( let bounds = layout.bounds(); - if let Some(cursor_position) = cursor.position_over(&bounds) { + if let Some(cursor_position) = cursor.position_over(bounds) { let style = theme.appearance(style); let defaults = renderer::Style { diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs index 47b14d57..91f2b466 100644 --- a/widget/src/vertical_slider.rs +++ b/widget/src/vertical_slider.rs @@ -304,8 +304,7 @@ where match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) | Event::Touch(touch::Event::FingerPressed { .. }) => { - if let Some(cursor_position) = - cursor.position_over(&layout.bounds()) + if let Some(cursor_position) = cursor.position_over(layout.bounds()) { change(cursor_position); state.is_dragging = true; @@ -355,7 +354,7 @@ pub fn draw<T, R>( R::Theme: StyleSheet, { let bounds = layout.bounds(); - let is_mouse_over = cursor.position_over(&bounds).is_some(); + let is_mouse_over = cursor.is_over(bounds); let style = if state.is_dragging { style_sheet.dragging(style) @@ -445,7 +444,7 @@ pub fn mouse_interaction( state: &State, ) -> mouse::Interaction { let bounds = layout.bounds(); - let is_mouse_over = cursor.position_over(&bounds).is_some(); + let is_mouse_over = cursor.is_over(bounds); if state.is_dragging { mouse::Interaction::Grabbing |