diff options
author | 2024-09-10 23:37:45 +0200 | |
---|---|---|
committer | 2024-09-10 23:39:49 +0200 | |
commit | c711750be7ccca6a6852d0222169ebfea04ee864 (patch) | |
tree | a4f2c6bb5aeadb844ade2782a14283eb4d6c7b7f /widget | |
parent | bf4796bbeb7a8274bf8eb32cfac51ad26de51681 (diff) | |
download | iced-c711750be7ccca6a6852d0222169ebfea04ee864.tar.gz iced-c711750be7ccca6a6852d0222169ebfea04ee864.tar.bz2 iced-c711750be7ccca6a6852d0222169ebfea04ee864.zip |
Use `cursor` changes to notify mouse events in `mouse_area`
Fixes #2433.
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/mouse_area.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/widget/src/mouse_area.rs b/widget/src/mouse_area.rs index d206322e..496afaa5 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -1,5 +1,4 @@ //! A container for capturing mouse events. - use crate::core::event::{self, Event}; use crate::core::layout; use crate::core::mouse; @@ -123,6 +122,8 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> { #[derive(Default)] struct State { is_hovered: bool, + bounds: Rectangle, + cursor_position: Option<Point>, } impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> { @@ -313,13 +314,17 @@ fn update<Message: Clone, Theme, Renderer>( cursor: mouse::Cursor, shell: &mut Shell<'_, Message>, ) -> event::Status { - if let Event::Mouse(mouse::Event::CursorMoved { .. }) - | Event::Touch(touch::Event::FingerMoved { .. }) = event - { - let state: &mut State = tree.state.downcast_mut(); + let state: &mut State = tree.state.downcast_mut(); + let cursor_position = cursor.position(); + let bounds = layout.bounds(); + + if state.cursor_position != cursor_position && state.bounds != bounds { let was_hovered = state.is_hovered; + state.is_hovered = cursor.is_over(layout.bounds()); + state.cursor_position = cursor_position; + state.bounds = bounds; match ( widget.on_enter.as_ref(), |