mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Hide arrow on TreeNode and Collapsibles when children are empty #324
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 assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#324
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?
When you're building a tree view it's nice to be able to keep all items at the same level aligned as well as hide the arrow on items which have no children.
Currently we're swapping between text items and borderless collapsibles and just putting 3 spaces before the text items which keeps everything roughly aligned but it that's really a fluke.
You can use BulletText() / Bullet() for that ?
Is there a way to hide the bullet graphic? This is really all about alignment, having the extra marker there is kind of annoying.
This is what we're trying to achieve
Indent()/Unindent() ?
All those things are variations around a same thing. It's trivial to create a custom helper if you need a different behavior.
The issue with indent is that it doesn't keep the labels at the indent computes for the bullet/expand arrow graphic. As soon as you start on a selectable treenode this behavior will probably be what you want as well.
Anyway it's fine, like you say. With 1.45 I can trivially add this behavior myself now.
I'm a little confused, could you elaborate with a more detailed example?
How would it look if you added more tree levels to your screenshot above?
Sure!
Common convention in tree views is to not provide an expander if there are not children to expand while obviously keeping all the text/icons aligned as though the expander was there. You can find this behavior in Windows Explorer, OSX and the Hierarchy view in Maya for example
This is a screen grab of a simple scene graph in our game. You'll notice that there are a number of nodes expanded yet do not have any children and are therefore kind of misleading.
Here's an example where I've caught most of them but again using my cheat by just inserting 3 spaces before a normal text widget when there are no children
So I suppose the problem here is that although you can do it with Indent(), you'd have to Indent/Unident manually for each item depending on whether the item is a tree node or not. Not a big problem for generated UI but still a still cumbersome and feels unnecessary?
I'll have to think of a solution on how to handle that neatly, I don't really know yet. If you have a suggestion.
The solution might to just change how tree node behave to follow this standard but that would require to start from an indented position for a first tree node to be consistent (aka tree node shows on the LEFT of the current cursor position). It's also less flexible for quick layout.
No, not at all. Using indent would be perfectly fine. However if you collapse Loxel Entities, There is actually a miss alignment on the labels.
Basically what I'm proposing is a flag on collapsible header prevents it from expanding and hides the arrow (something to the effect of "ImGui_DisableCollapse". Or a bullet text that can have an empty bullet I guess, but It seems like it should really just be on the collapsible.
So my current approach has been to simply make a copy of the BulletTextV and comment out the
window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));FYI @kylawl I have fixed a bug today with indenting within trees with might affect your code - not specifically related to the main topic of this thread, but on your property widget. I am not sure how you got the right column to align correctly in this screenshot, did you reposition the cursor on the X axis? What does the code looks like? Anyway, if you have time to double-check it with the latest fixes it'd be super helpful. Thanks :)
For each time I enter the right hand column I call ImGui::PushItemWidth(-1.0f);
What I ended up doing for the label was just copying the collapsible header and removing the rendering of the arrow
Looking at this today along with several other TreeNode related issues, and I think what we could do is add a flag, .e.g
ImGuiTreeNodeFlags_UnindentArrowthe modify the tree behavior to allow this with more ease. It would probably require the user to manually Indent() once at the beginning to leave room for the arrow, may alter Indent() to be more flexible.Just theorizing at this point, I'm looking at all those Tree issues and trying to come with a general design.
(exact details left to be decided).
I managed to get a version of TreeNodeEx working, which took some flags and
allowed arrow hiding and node selection. I will post some code in a couple
of days but it's not integrated with the main code yet.
On Sun, 24 Apr 2016 at 06:18 omar notifications@github.com wrote:
Thinking out loud here..
This topic is made confusing partly because collapsing triangles are using
FontSize + FramePadding.x*2amount of width and within the tree we ident withstyle.IndentSpacing.With default settings:
(A)
FontSize + FramePadding.x*2 = 13+4*2 == 21and
(B)
IndentSpacing == 22So things appears to lines up perfectly.
Note that the equation leading to (A) is never explicitly mentioned anywhere.
Now, within a large tree it is useful to alter and reduce IndentSpacing to save horizontal space. With the tree scheme pushed by ImGui it isn't a problem that (A) != (B).
And BulletText() also uses
FontSize + FramePadding.x*2FYI.Where this becomes a problem is when you want to want to introduce a concept of "leaf", because there's different ways to define what a leaf may be. In most of examples provided by @Cthutu and @kylawl you are showing one-liner label leaves, which are equivalent to calling BulletText(), and no other items. In this situation it doesn't matter that (A) and (B) may have different values.
(A) == 21, (B) == 22
(A) == 21, (B) == 14, no problem.
However, once you want to go not one-liner, and add extra content in the leaf item, (A) and (B) being different cause a problem.
(A) == 21, (B) == 14
It's not a big problem, but the fact that
Makes thing more confusing.
Solution could involve a mix of some of those tasks:
Ideally that would have been easier from day 1 if tree label where displayed at the current cursor X position and the arrow was displayed to the left of that (which is what the proposal flag would do) - going to experiment with that and consider side-effects.
AFAIK your initial request should be full-fillled.
You can use either:
@kylawl @Cthutu would be nice to confirm!
Also added an example of basically doing:
Effectively making the text label of the node aligned with the current X position.
Originally aimed at adding a flag e.g.
ImGuiTreeNodeFlags_Unindenthowever this the unindented amount would need to stored to allow TreePop() to undo it, so would need to turn Indent/Unindent to be stack based, and I'd rather avoid adding extra heap usage until we extend ImVector to carry an optional local buffer. Either way I believe it is just easier and more logical to un-indent once.To replicate

The more natural way is still to just call TreeAdvanceToLabelPos() + Text().