-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Drag'n drop support #143
Comments
Do you mean drag and dropping of files into your application window? I suppose we can consider to add helpers for common known platforms (such as Windows) to help setting up drag'n drop if there was an easy way to do so. But ImGui doesn't know about concept of windows messages. So it'll probably be a little convoluted for what's essentially replacing 10 lines of code. If you are asking from the angle of "I may have two widgets with same string", the ID are built from a stack of strings that include the window, tree nodes, and which you can push into. So typically when creating repeated widgets in a loop you need to use PushID/PopID to manipulate the ID stack and make the sub-elements unique. If you are asking from the angle of "what if even with the precaution above, CRC32 collision occurs ".
In fact, if anything, CRC32 is too slow and we should try to replace it with a faster hash function. |
|
The draggable object can behave as a button, but when active it draws itself following the mouse cursor. That needs to be be done by pushing a fullscreen clipping rectangle. Along with setting g,ActiveId it can set g.DraggingId and g.DraggingData. (Bonus: It also need to be in a front-most ImDrawList. There's no explicit mechanism for that yet. Things like Tooltip are implicitly high-up in the draw order. Need to improve on explicitly deciding of a sort order. But for a start you don't need that anyway because the parent window of the draggable object will front-most already as soon as you click it. That is, until we implement "hold dragged object on another window to bring it to top". )
Pseudo-code
See what happens. |
About CRC32 collision: While it's not impossible that a collision happens my bet is that:
For persistent storage such as TreeNode open/close state and Column offsets they are stored per-window so won't collide accross windows, and could potentially be stored in separate maps per usage (e.g. tree nodes vs columns). This is all a non-problem really. |
For drag'n drop : yes, it might be something as you propose. For crc, okay, i'll try (though I don't like voodoo :) ) Thanks for your answers. |
FYI with IsItemActive() and GetMouseDragDelta() there's a few stuff that can already be done now. I did a quick hacky test for someone who wanted to know if re-ordering was possible:
That could be done in a nicer and more sturdy way within the core library eventually. Another possibility is to render out of order by manipulating the cursor position, but I think the way above fits better with the typical data structure. |
these sort of things shouldn't be buried inside of tickets but be a listed in some kind of wiki |
Yes definitively, but it's still experimental here, and pretty hacky/broken (won't work with scrolling, in fact it will even exhibit a bug where active items aren't releasing the active flag when they are clipped even when the mouse button is released). I really want to do a wiki with lots of demos. I wlll eventually. |
…ate (mentioned in #143) Otherwise a change in layout moving active widget to a clipped region may lock the active id.
@Roflraging posted his own use of dragging to reorder widgets: In spite of the extra faff with the copying of his data structures, his approach of recording the index of the hovered fields is more robust and flexible. There's actually very little ImGui code too. I'll rewrite an example using this technique. I think the post-it could be moved to match the original widget position pretty easily. In one of my test (not published) I actually pushed a no-clipping-rectangle and redrawn the same widget following the mouse, which can also work. Following this base if it's deemed robust enough we can probably come up with helpers. |
awesome. showing the widget at the mouse is a must-have for drag/drop imho |
I noticed in the code I copied into the gist that one of the comments was wrong, sorry if anybody was confused! https://gist.github.com/Roflraging/f4af1d688237a7d367f9#file-gistfile1-cpp-L93 https://gist.github.com/Roflraging/f4af1d688237a7d367f9/revisions |
@ocornut did you rewrite that example that you mentioned ? |
Sorry I haven't got around to write an example for that (that's why I kept the issue opened for now) |
I'm curious how do you do something on a "drop"? |
Right now you would have to track the dragging state, and then on mouse release test for item overlapping the mouse cursor. Something like It could/should probably be wrapped into a helper function but we haven't got a standard way of storing the dragging state yet, so this is left to you to do the test above. |
+1 for a working example similar to the GIF above, with perhaps a more complex drag object that demonstrates layouting as well? What also interests me is highlighting the insertion point upon hover, depending on proximity, or changing a drop targets appearance when someone is dragging over it. |
Adding something more interesting to the examples would be nice. Currently the only thing I can find is the "dragging" example under "keyboard/mouse/focus" which seems pretty buried - and not very clear as to how it would be useful, unlike the examples in this issue. Would a patch to the examples code implementing your draggable list example be something you'd be interested in? |
Will do eventually. Some recent links: LumixEngine Paniq using his crazy language |
@extrawurst, are you going to share that snippet? Seems very useful for the imgui community! |
It is not a snippet, it's buried in my engine but it was based on the gist above |
Everyone: I will maybe be able to look at drag'n drop in the upcoming weeks/months, or at least just enough to contemplate using a standard drag'n drop api for Tabs and Docking. Maybe the early versions of course feature won't use a standard drag'n drop api but ultimately this may be the ideal goal so I'll keep that in mind. If anyone has feedback or request on drag'n drop features please voice them! |
… more specific behavior. Will enable improvements for popups/context menus and drag'n drop. (relate ~#439, #1013, #143, #925) The legacy confusing IsItemRectHovered(), IsWindowRectHovered() can be completely removed now. Changed IsWindowHovered() behavior with default parameter: it now return false is the window is blocked by a popup. Demo: Added tests for those two functions.
…widget from another window is active + Added support for ImGuiHoveredFlags_AllowWhenBlockedByActiveItem. (relate to drag'n drop idoms: #143)
If you are using drag'n drop idioms in your codebase, please read this thread: #1382 |
…source tooltip from the target site (#143)
…t hovering state prior to calling IsItemHovered() + fixed description. (#143)
…DragSource() or BeginDropTarget()/EndDropTarget() uses adjusted tooltip settings matching the one created when calling BeginDragSource() without the ImGuiDragDropFlags_SourceNoPreviewTooltip flag. (#143) + additional safety checks.
…dDrop() + BeginDragDropTargetCustom() can't succeed with hidden contents. (#143)
…ayload (if any) from anywhere. (#143)
This is working super well for me in it's current state. A small note is that the held-item preview tooltip turns into I am not sure if that would violate some ImGui internal rules or limitations, but couldn't the draw list for the node be cached? That behavior could be toggle-able via a Source-DragDropFlag in case you know that you would rather want no tooltip than a non-realtime one. |
Hi. |
@ChugunovRoman this is backend-specific. For example SDL sends @ocornut shouldnt this issue be closed? Drag & drop is implemented. |
I tend to keep issue opens when some of the posts are discussing interesting/useful ideas that are still yet to implement and not covered elsewhere. There are a few things discussed here that are still unfullfilled:
I'll close this issue as the points raised above are all listed in TODO.txt, when there is an impulse/attempt to solve them it we can open a new issue to discuss them. Thanks all! |
I implemented exactly this in my engine editor by adding extra few pixel high drop areas between list items. For this however i had to modify imgui to have smaller drop area border margins. I should make a PR for this margin to be configurable via style.. |
PR of a small demo would be helpful, I can think of two ways to do it:
Feel free to open an issue/PR to discuss this further. |
…ither _OpenOnDoubleClick or _OpenOnArrow would open the node. (#143)
…lowNullID doesn't lose tooltip when scrolling. (#143) Reduced amount of self critical commentary since it'll appear like a hack for users but it isn't more a hack than many other things.
…lowNullID doesn't lose tooltip when scrolling. (ocornut#143) Reduced amount of self critical commentary since it'll appear like a hack for users but it isn't more a hack than many other things.
…before payload is submitted. (ocornut#5910, ocornut#143) + Added test "widgets_dragdrop_new_payloads" in Test Suite.
…tern assume a mouse button being pressed. (#143)
hi, I'm considering using ImGui (to convert ooold mfc game tool),
but one lacking thing is the support for drag'n'drop.
Is this feature planned ?
If no, I'll try to hack something in..
thanks for your work !
Ps: Side Question : concerning the uniqueness of Ids, err.. relying on a string crc32 seems weak to me. If I use ImGui for editing data, collisions might occur, and if so, I have no way of knowing if it happened.
Am I missing something ?
The text was updated successfully, but these errors were encountered: