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 François Mockers
parent 49560aeee5
commit d2fbedbe6f

View File

@ -657,6 +657,10 @@ pub fn pointer_events(
// Emit Drag events to the entities we are dragging
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(
*drag_target,
pointer_id,
@ -664,7 +668,7 @@ pub fn pointer_events(
Drag {
button,
distance: location.position - drag.start_pos,
delta: location.position - drag.latest_pos,
delta,
},
);
commands.trigger_targets(drag_event.clone(), *drag_target);