Skip to content

Commit

Permalink
Use cursor changes to notify mouse positions in mouse_area
Browse files Browse the repository at this point in the history
Fixes #2433.
  • Loading branch information
hecrj committed Sep 10, 2024
1 parent bf4796b commit 0806f2f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions widget/src/mouse_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point>,
}

impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> {
Expand Down Expand Up @@ -313,13 +315,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(),
Expand Down

0 comments on commit 0806f2f

Please sign in to comment.