From 0806f2f6bda0aff87c0d04a78985776c9007dc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 10 Sep 2024 23:37:45 +0200 Subject: [PATCH] Use `cursor` changes to notify mouse positions in `mouse_area` Fixes #2433. --- widget/src/mouse_area.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/widget/src/mouse_area.rs b/widget/src/mouse_area.rs index d206322e29..21747530fc 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -123,6 +123,8 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> { #[derive(Default)] struct State { is_hovered: bool, + bounds: Rectangle, + cursor_position: Option, } impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> { @@ -313,13 +315,17 @@ fn update( 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(),