fix(dnd): leave event handlers should expect None as the drag Id

This commit is contained in:
Ashley Wulber 2025-05-20 22:28:57 -04:00 committed by Michael Murphy
parent a46483f161
commit ce56237ab9
3 changed files with 17 additions and 7 deletions

View file

@ -241,6 +241,11 @@ impl<'a, Message: 'static> DndDestination<'a, Message> {
Internal::Set(_) => panic!("Invalid Id assigned to dnd destination."), Internal::Set(_) => panic!("Invalid Id assigned to dnd destination."),
})) }))
} }
pub fn id(mut self, id: Id) -> Self {
self.id = id;
self
}
} }
impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer> impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
@ -354,8 +359,12 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
} }
return event::Status::Captured; return event::Status::Captured;
} }
Event::Dnd(DndEvent::Offer(id, OfferEvent::Leave)) if id == Some(my_id) => { Event::Dnd(DndEvent::Offer(id, OfferEvent::Leave)) => {
state.on_leave(self.on_leave.as_ref().map(std::convert::AsRef::as_ref)); if let Some(msg) =
state.on_leave(self.on_leave.as_ref().map(std::convert::AsRef::as_ref))
{
shell.publish(msg);
}
if self.forward_drag_as_cursor { if self.forward_drag_as_cursor {
let drag_cursor = mouse::Cursor::Unavailable; let drag_cursor = mouse::Cursor::Unavailable;
@ -403,7 +412,7 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
} }
return event::Status::Captured; return event::Status::Captured;
} }
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) if id == Some(my_id) => { Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) => {
if let Some(msg) = if let Some(msg) =
state.on_leave(self.on_leave.as_ref().map(std::convert::AsRef::as_ref)) state.on_leave(self.on_leave.as_ref().map(std::convert::AsRef::as_ref))
{ {

View file

@ -733,9 +733,8 @@ where
entity, entity,
); );
} }
DndEvent::Offer(id, OfferEvent::Leave | OfferEvent::LeaveDestination) DndEvent::Offer(id, OfferEvent::LeaveDestination) if Some(my_id) != *id => {}
if Some(my_id) == *id => DndEvent::Offer(id, OfferEvent::Leave | OfferEvent::LeaveDestination) => {
{
if let Some(Some(entity)) = entity { if let Some(Some(entity)) = entity {
if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() { if let Some(on_dnd_leave) = self.on_dnd_leave.as_ref() {
shell.publish(on_dnd_leave(entity)); shell.publish(on_dnd_leave(entity));

View file

@ -1995,10 +1995,12 @@ pub fn update<'a, Message: Clone + 'static>(
return event::Status::Ignored; return event::Status::Ignored;
} }
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
Event::Dnd(DndEvent::Offer(id, OfferEvent::LeaveDestination)) if Some(dnd_id) != id => {}
#[cfg(feature = "wayland")]
Event::Dnd(DndEvent::Offer( Event::Dnd(DndEvent::Offer(
rectangle, rectangle,
OfferEvent::Leave | OfferEvent::LeaveDestination, OfferEvent::Leave | OfferEvent::LeaveDestination,
)) if rectangle == Some(dnd_id) => { )) => {
cold(); cold();
let state = state(); let state = state();
// ASHLEY TODO we should be able to reset but for now we don't if we are handling a // ASHLEY TODO we should be able to reset but for now we don't if we are handling a