Skip to content

Pointer<Drag> event delta depends on scale factor #19754

Open
@arcln

Description

@arcln

Bevy version

0.16

What you did

I tried to implement a draggable window using bevy UI and the Pointer event.

(
    Window,
    Node {
        position_type: PositionType::Absolute,
        left: Val::Px(100.0),
        top: Val::Px(100.0),
        width: Val::Px(600.0),
        height: Val::Px(300.0),
        ..Default::default()
    },
    children![
        // ...
    ],
    observers![|mut trigger: Trigger<Pointer<Drag>>,
                mut windows: Query<&mut Node, With<Window>>| {
        let Ok(mut window_node) = windows.get_mut(trigger.target()) else {
            return;
        };

        let Val::Px(left) = window_node.left else {
            return;
        };
        let Val::Px(top) = window_node.top else {
            return;
        };

        window_node.left = Val::Px(left + trigger.delta.x);
        window_node.top = Val::Px(top + trigger.delta.y);

        trigger.propagate(false);
    }],
)

What went wrong

The window does follow the drag movement but there is a multiplier to the movement speed. This multiplier depends on which child node I drag on. For example, dragging from the empty space will work normally, but dragging with the pointer on child text will result in different speed movement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions