From 69e37395fe5ad9d7796d9dda3ee76dbe0b0b60b7 Mon Sep 17 00:00:00 2001 From: Matt George Date: Sat, 4 Jan 2025 03:42:46 -0700 Subject: [PATCH] move drag_initiated clear to beginning of update fn --- widget/src/mouse_area.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/widget/src/mouse_area.rs b/widget/src/mouse_area.rs index 1ce5001858..9705798028 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -401,6 +401,22 @@ fn update( let state: &mut State = tree.state.downcast_mut(); let cursor_position = cursor.position(); + if let Some(drag_source) = state.drag_initiated { + if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) + | Event::Touch(touch::Event::FingerLifted { .. }) = event + { + if let Some(position) = cursor_position { + if position.distance(drag_source) <= 1.0 { + state.drag_initiated = None; + } + } + } + + if let Event::Touch(touch::Event::FingerLost { .. }) = event { + state.drag_initiated = None; + } + } + if let Event::Mouse(mouse::Event::CursorMoved { .. }) | Event::Touch(touch::Event::FingerMoved { .. }) = event { @@ -464,7 +480,6 @@ fn update( state.last_click = Some(click); if let mouse::click::Kind::Double = click.kind() { shell.publish(message.clone()); - state.drag_initiated = None; return event::Status::Captured; } } @@ -510,7 +525,6 @@ fn update( if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) | Event::Touch(touch::Event::FingerLifted { .. }) = event { - state.drag_initiated = None; shell.publish(message.clone()); return event::Status::Captured;