Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking the mouse once will also trigger DragStart and DragEnd #17230

Closed
rendaoer opened this issue Jan 8, 2025 · 0 comments
Closed

Clicking the mouse once will also trigger DragStart and DragEnd #17230

rendaoer opened this issue Jan 8, 2025 · 0 comments
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@rendaoer
Copy link
Contributor

rendaoer commented Jan 8, 2025

Bevy version

v0.15.1

What you did

Yes, Drag is fixed, but what about DragStart and DragEnd? Why are they triggered even when there is no movement?

What went wrong

In theory, a click of the mouse should only trigger Down and Up, and DragStart and DragEnd should not be triggered.

Additional information

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2d);

    commands
        .spawn((
            Sprite {
                color: Color::srgb(1.0, 0.0, 0.0),
                custom_size: Some(Vec2::new(100.0, 100.0)),
                ..default()
            },
            Transform::from_xyz(0.0, 0.0, 0.0),
        ))
        .observe(down_handler)
        .observe(up_handler)
        .observe(drag_start_handler)
        .observe(drag_handler)
        .observe(drag_end_handler);
}

fn down_handler(_: Trigger<Pointer<Down>>) {
    info!("Down");
}

fn up_handler(_: Trigger<Pointer<Up>>) {
    info!("Up");
}

fn drag_start_handler(_: Trigger<Pointer<DragStart>>) {
    info!("DragStart");
}

fn drag_handler(_: Trigger<Pointer<Drag>>) {
    info!("Drag");
}

fn drag_end_handler(_: Trigger<Pointer<DragEnd>>) {
    info!("DragEnd");
}
@rendaoer rendaoer added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 8, 2025
@BenjaminBrienen BenjaminBrienen added A-Input Player input via keyboard, mouse, gamepad, and more S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! D-Straightforward Simple bug fixes and API improvements, docs, test and examples and removed S-Needs-Triage This issue needs to be labelled labels Jan 8, 2025
github-merge-queue bot pushed a commit that referenced this issue Jan 9, 2025
# Objective

Fixed the issue where DragStart was triggered even when there was no
movement
#17230

## Solution

- When position delta is zero, don't trigger DragStart events, DragStart
is not triggered, so DragEnd is not triggered either. Everything is
fine.

## Testing

- tested with the code from the issue

---

## Migration Guide

> Fix the missing part of Drag
#16950
@rendaoer rendaoer closed this as completed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

No branches or pull requests

2 participants