Skip to content

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

Merged
emilk merged 24 commits intomasterfrom
emilk/drag-and-drop
Jan 29, 2024
Merged

Add drag-and-drop APIs with payloads storage#3887
emilk merged 24 commits intomasterfrom
emilk/drag-and-drop

Conversation

@emilk
Copy link
Copy Markdown
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 force-pushed the emilk/drag-and-drop branch from 264ec2d to ca0dc07 Compare January 25, 2024 12:13
@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 force-pushed the emilk/drag-and-drop branch from 5123501 to e1a7b32 Compare January 25, 2024 18:59
@emilk emilk force-pushed the emilk/drag-and-drop branch from d9b91a3 to f2eeacf Compare January 25, 2024 19:22
@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
Copy Markdown
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.

@emilk
Copy link
Copy Markdown
Owner Author

emilk commented Jan 29, 2024

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

@abey79
Copy link
Copy Markdown
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
@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