mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Nested group hovering detection and group dragging? #479
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#479
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi Omar!
I was working on a GUI feature on my game where we could take array elements and click and drag them to reorder. I ran into a case where each array element was another array and the logic I was using involved groups to help detect the whole area used up by an element (rather than just each component widget).
The problem I ran into was that I couldn't determine correctly the nested group hovering. It would return to me the "top level" group as being hovered, despite the nested group being just finished.
Here's a test case:
Should I just be using BeginChild()/EndChild() here? The thing I like about groups is that it just becomes the size of the space taken up by widgets between the begin/end calls. BeginChild() I have to specify a size ahead of time. Am I missing something?
The other thing I was wondering is if there's some easy way for me to work in clicking and dragging the group? What I want to do is basically treat the entire region encompassed by the group as something I can click and drag, but currently if you begin click and dragging in a non-widget area of the window, it just starts performing the window moving logic. Basically, I want to disable the window moving logic temporarily... or somehow let the group itself be an interactable "widget" as well.
-Dale Kim
Hi Dale,
Both groups would return true to IsItemHovered(). SetTooltip() overwrite existing tooltip if any so I am seeing "Group A" in this repro but if I comment out the SetTooltip("Group A") - or modify the feedback - it shows that "Group B" is hovered as well.
So based on this I believe the code in ImGui is correct? And it may be a case of re-organizing your code knowing that to consider the nested-most item only.
Some ideas toward your later question, you could possibly create an invisible button at the END of each group so the empty area can be caught. Or, you can create an invisible button at the beginning to cover the entire window and/or known group size, record the active/hovered state then call SetItemAllowOverlap() to also further visible items to be used. Bit awkward but it should work. If you use that sort of pattern and have an idea how they could be simplified let me know :)
Ah yes, you're correct on that! My expectations of IsItemHovered() was wrong. The query I want to be making is something along the lines of: "What item is the mouse currently hovering over?" and "If that item is the last item" do something. I'll try rearranging or modifying my code to detect the nested case.
With regard to the invisible button, I'll try that out and let you know how it goes! In fact, this might nullify my need to do this IsItemHovered() + groups hack at all...
Sorry, I totally forgot about this issue!
I found a good workaround for this by using your suggestion of an invisible button at the end of the "group":
https://www.youtube.com/watch?v=uWEOWp0zE_g&feature=youtu.be
https://www.youtube.com/watch?v=ice2oLxIqa8&feature=youtu.be
The code looks like this:
Excuse the game specific code here, but it's very simple. Just remember the cursor position before doing the GUI elements. After GUI is done, find the current cursor position so you can create a button of the proper height. Reset cursor to the starting position before the GUI elements and create the button!
Everything falls nicely into place; input events are sent directly to the intended buttons when interacting with the normal GUI portion. The only thing that's iffy here is that it isn't obvious that you can drag things around or what the region actually is, but for us it's not a big deal. It's just understood that the label is draggable.
-Dale Kim
Good to hear!
(video with "visible" buttons looking very odd obviously)
You could display a rectangle outline or fill around the entire zone when hovered.
If you can bother using the ImDrawList::ChannelSplit api so you also draw out of the order if this is easier to your code and you want a filled rectangle, so you could possibly draw the background after the fact.
Closing this afaik this is a closed topic?
Yep, closed! Thanks Omar!
On Sunday, April 3, 2016, omar notifications@github.com wrote: