don't trigger drag events if there's no movement (#16950)

# Objective

- Fixes #16571

## Solution

- When position delta is zero, don't trigger `Drag` or `DragOver` events

## Testing

- tested with the code from the issue
This commit is contained in:
François Mockers 2024-12-24 04:15:13 +01:00 committed by GitHub
parent 99c869d58d
commit 4acb34ee34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -692,6 +692,10 @@ pub fn pointer_events(
// Emit Drag events to the entities we are dragging // Emit Drag events to the entities we are dragging
for (drag_target, drag) in state.dragging.iter_mut() { for (drag_target, drag) in state.dragging.iter_mut() {
let delta = location.position - drag.latest_pos;
if delta == Vec2::ZERO {
continue; // No need to emit a Drag event if there is no movement
}
let drag_event = Pointer::new( let drag_event = Pointer::new(
pointer_id, pointer_id,
location.clone(), location.clone(),
@ -699,7 +703,7 @@ pub fn pointer_events(
Drag { Drag {
button, button,
distance: location.position - drag.start_pos, distance: location.position - drag.start_pos,
delta: location.position - drag.latest_pos, delta,
}, },
); );
commands.trigger_targets(drag_event.clone(), *drag_target); commands.trigger_targets(drag_event.clone(), *drag_target);