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

Add drag-and-drop APIs with payloads storage #3887

Merged
merged 24 commits into from
Jan 29, 2024
Merged

Conversation

emilk
Copy link
Owner

@emilk emilk commented Jan 25, 2024

This adds several methods to make drag-and-drop more ergonomic in egui.

In particular, egui can now keep track of what is being dragged for you (the payload).

Low-level:

  • egui::DragAndDrop hold the payload during a drag

Mid-level:

  • Response::dnd_set_drag_payload sets it for drag-sources
  • Response::dnd_hover_payload and Response::dnd_release_payload reads it for drop-targets

High-level:

  • ui.dnd_drag_source: make a widget draggable
  • ui.dnd_drop_zone: a container where things can be dropped

The drag-and-drop demo is now a lot simpler:

https://github.com/emilk/egui/blob/emilk/drag-and-drop/crates/egui_demo_lib/src/demo/drag_and_drop.rs

@emilk emilk added the egui label Jan 25, 2024
@emilk emilk force-pushed the emilk/drag-and-drop branch 3 times, most recently from 7ffd062 to 4d164ce Compare January 25, 2024 16:49
@emilk emilk marked this pull request as ready for review January 25, 2024 19:48
@emilk emilk requested a review from abey79 January 25, 2024 19:48
@emilk emilk changed the title Add API for storing drag-and-drop payload Add APIs for drag-and-drop payloads Jan 25, 2024
@emilk emilk changed the title Add APIs for drag-and-drop payloads Add drag-and-drop APIs with payloads storage Jan 25, 2024
Copy link
Collaborator

@abey79 abey79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only able to use the low-level API in rerun, because of all the geometry testing I must run on my side, but the ability to store and retrieve the dnd payload (along with using its existence as a marker of on on-going drag) makes the code much cleaner and easy to reason with.

crates/egui/src/drag_and_drop.rs Outdated Show resolved Hide resolved
@emilk
Copy link
Owner Author

emilk commented Jan 29, 2024

@abey79 Oh, you can't even use the Response API? :(

@abey79
Copy link
Collaborator

abey79 commented Jan 29, 2024

@emilk The response API works well when moving boxes inside boxes, but not so well when moving boxes in-between boxes :)

@emilk emilk merged commit abd028b into master Jan 29, 2024
35 checks passed
@emilk emilk deleted the emilk/drag-and-drop branch January 29, 2024 10:14
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
* Closes emilk#3882

This adds several methods to make drag-and-drop more ergonomic in egui.

In particular, egui can now keep track of _what_ is being dragged for
you (the _payload_).

Low-level:
* `egui::DragAndDrop` hold the payload during a drag

Mid-level:
* `Response::dnd_set_drag_payload` sets it for drag-sources
* `Response::dnd_hover_payload` and `Response::dnd_release_payload`
reads it for drop-targets

High-level:
* `ui.dnd_drag_source`: make a widget draggable
* `ui.dnd_drop_zone`: a container where things can be dropped

The drag-and-drop demo is now a lot simpler:


https://github.com/emilk/egui/blob/emilk/drag-and-drop/crates/egui_demo_lib/src/demo/drag_and_drop.rs

---------

Co-authored-by: Antoine Beyeler <abeyeler@ab-ware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improvements to make drag-and-drop easier
2 participants