Skip to content

Commit 58ab077

Browse files
committed
fix(dnd): leave event handlers should expect None as the drag Id
1 parent a46483f commit 58ab077

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/widget/dnd_destination.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ impl<'a, Message: 'static> DndDestination<'a, Message> {
241241
Internal::Set(_) => panic!("Invalid Id assigned to dnd destination."),
242242
}))
243243
}
244+
245+
pub fn id(mut self, id: Id) -> Self {
246+
self.id = id;
247+
self
248+
}
244249
}
245250

246251
impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
@@ -354,8 +359,12 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
354359
}
355360
return event::Status::Captured;
356361
}
357-
Event::Dnd(DndEvent::Offer(id, OfferEvent::Leave)) if id == Some(my_id) => {
358-
state.on_leave(self.on_leave.as_ref().map(std::convert::AsRef::as_ref));
362+
Event::Dnd(DndEvent::Offer(id, OfferEvent::Leave)) => {
363+
if let Some(msg) =
364+
state.on_leave(self.on_leave.as_ref().map(std::convert::AsRef::as_ref))
365+
{
366+
shell.publish(msg);
367+
}
359368

360369
if self.forward_drag_as_cursor {
361370
let drag_cursor = mouse::Cursor::Unavailable;
@@ -403,7 +412,7 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
403412
}
404413
return event::Status::Captured;
405414
}
406-
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) if id == Some(my_id) => {
415+
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) => {
407416
if let Some(msg) =
408417
state.on_leave(self.on_leave.as_ref().map(std::convert::AsRef::as_ref))
409418
{

src/widget/segmented_button/widget.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,8 @@ where
733733
entity,
734734
);
735735
}
736-
DndEvent::Offer(id, OfferEvent::Leave | OfferEvent::LeaveDestination)
737-
if Some(my_id) == *id =>
738-
{
736+
DndEvent::Offer(id, OfferEvent::LeaveDestination) if Some(my_id) != *id => {}
737+
DndEvent::Offer(id, OfferEvent::Leave | OfferEvent::LeaveDestination) => {
739738
if let Some(Some(entity)) = entity {
740739
if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() {
741740
shell.publish(on_dnd_leave(entity));

src/widget/text_input/input.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,10 +1995,12 @@ pub fn update<'a, Message: Clone + 'static>(
19951995
return event::Status::Ignored;
19961996
}
19971997
#[cfg(feature = "wayland")]
1998+
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) if Some(dnd_id) != id => {}
1999+
#[cfg(feature = "wayland")]
19982000
Event::Dnd(DndEvent::Offer(
19992001
rectangle,
20002002
OfferEvent::Leave | OfferEvent::LeaveDestination,
2001-
)) if rectangle == Some(dnd_id) => {
2003+
)) => {
20022004
cold();
20032005
let state = state();
20042006
// ASHLEY TODO we should be able to reset but for now we don't if we are handling a

0 commit comments

Comments
 (0)