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

Improvements to make drag-and-drop easier #3882

Closed
abey79 opened this issue Jan 24, 2024 · 4 comments · Fixed by #3887
Closed

Improvements to make drag-and-drop easier #3882

abey79 opened this issue Jan 24, 2024 · 4 comments · Fixed by #3887

Comments

@abey79
Copy link
Collaborator

abey79 commented Jan 24, 2024

  • Add some drag-and-drop-related APIs in Response and Memory #3876 added men.dragged_id(), but there is no way to get the value of to an egui::Id (which could then be converted to an internal Id).
  • It would be nice to have ctx().anything_being_decidedly_dragged() (equivalent to ui.memory(|mem| mem.is_anything_being_dragged()) && ui.input(|i| i.pointer.is_decidedly_dragging())
  • It would be nice to have ctx().drag_stopped()
@emilk
Copy link
Owner

emilk commented Jan 24, 2024

We should take a look at the Dear ImGui API for drag-and-drop

@emilk emilk added the egui label Jan 24, 2024
@crumblingstatue
Copy link
Contributor

I want to mention egui_dnd just as a baseline to compare an egui-builtin solution against.

It only seems to support fairly simple layouts.

I would like something that supports drag and drop between different uis for maximum flexibility.

An example use case of mine would be to drag tree nodes in a tree.

For example move a-1 to b in this tree ui made out of CollapsingHeaders.
image

@abey79
Copy link
Collaborator Author

abey79 commented Jan 25, 2024

@crumblingstatue I think a proper high-level drag-and-drop API in egui is still a little far off due to the difficulty to properly address the general case(s). This issue is more about the little things that would make lower-level implementation easier.

As for the tree drag-and-drop, I just built a demo of that in the rerun repository: rerun-io/rerun#4879. I plan on making a proper egui example out of it.

@abey79
Copy link
Collaborator Author

abey79 commented Jan 27, 2024

@crumblingstatue #3903

emilk added a commit that referenced this issue Jan 29, 2024
* Closes #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>
hacknus pushed a commit to hacknus/egui that referenced this issue 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants