From 3d2c018cd1df25697fa2825dbc5d040cff39389a Mon Sep 17 00:00:00 2001 From: Ashley Wulber <48420062+wash2@users.noreply.github.com> Date: Fri, 6 Mar 2026 14:37:56 -0500 Subject: [PATCH] fix(dnd_source): rely on current cursor position for hover state --- iced | 2 +- src/widget/dnd_source.rs | 51 +++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/iced b/iced index 0214976..ac24bbe 160000 --- a/iced +++ b/iced @@ -1 +1 @@ -Subproject commit 02149769ec61d485ddc0bf4f07e98f0ec700420f +Subproject commit ac24bbe80dd16ea586b8a0b5816066e3ba1b48fa diff --git a/src/widget/dnd_source.rs b/src/widget/dnd_source.rs index 07b448a..25900a6 100644 --- a/src/widget/dnd_source.rs +++ b/src/widget/dnd_source.rs @@ -240,7 +240,7 @@ impl match mouse_event { mouse::Event::ButtonPressed(mouse::Button::Left) => { if let Some(position) = cursor.position() { - if !state.hovered { + if !cursor.is_over(layout.bounds()) { return; } @@ -256,33 +256,27 @@ impl { if let Some(position) = cursor.position() { - if state.hovered { - // We ignore motion if we do not possess drag content by now. - if self.drag_content.is_none() { - state.left_pressed_position = None; - return; + // We ignore motion if we do not possess drag content by now. + if self.drag_content.is_none() { + state.left_pressed_position = None; + return; + } + if let Some(left_pressed_position) = state.left_pressed_position + && position.distance(left_pressed_position) > self.drag_threshold + { + if let Some(on_start) = self.on_start.as_ref() { + shell.publish(on_start.clone()); } - if let Some(left_pressed_position) = state.left_pressed_position { - if position.distance(left_pressed_position) > self.drag_threshold { - if let Some(on_start) = self.on_start.as_ref() { - shell.publish(on_start.clone()) - } - let offset = Vector::new( - left_pressed_position.x - layout.bounds().x, - left_pressed_position.y - layout.bounds().y, - ); - self.start_dnd(clipboard, state.cached_bounds, offset); - state.is_dragging = true; - state.left_pressed_position = None; - } - } - if !cursor.is_over(layout.bounds()) { - state.hovered = false; - - return; - } - } else if cursor.is_over(layout.bounds()) { - state.hovered = true; + let offset = Vector::new( + left_pressed_position.x - layout.bounds().x, + left_pressed_position.y - layout.bounds().y, + ); + self.start_dnd(clipboard, state.cached_bounds, offset); + state.is_dragging = true; + state.left_pressed_position = None; + } + if !cursor.is_over(layout.bounds()) { + return; } shell.capture_event(); } @@ -296,7 +290,6 @@ impl { @@ -306,7 +299,6 @@ impl (), @@ -422,7 +414,6 @@ impl< /// Local state of the [`MouseListener`]. #[derive(Debug, Default)] struct State { - hovered: bool, left_pressed_position: Option, is_dragging: bool, cached_bounds: Rectangle,