-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
What's the proper way to render custom text or custom items in the "key"/"label" of a TreeNode? #7505
Comments
I don't think there is a "clean" way to do this. If you want to replicate the offset exactly, you can find how to calculate it in the first few lines of Still a hack, but maybe a bit cleaner since you won't need to replicate calculations: you could add a singular space as a label and adjust the cursor position by the width of that space. Still better (in case you want f.e. navigation rects of the correct size): you can submit a full size label with all characters replaced by spaces. and adjust the cursor position by the entire text width. That should work as long as you don't use a proportional custom font. |
It seems like a bug to me that |
I'm sincerely surprised this has not been submitted before. By sheer accident, with the default style settings if you do what you did ( If I rewind history, the code was notably modified in 370de41, some refactor 4006fb7, split layout vs interact bb in c381d58, The later is what introduced the I'll push a fix soon. |
:( Ill probably end up going with some sort of space padded solution to maintain the ability to click on the label or just doing it via |
You probably want to use |
I've pushed a fix 361432a however this is a breaking fix, and I need to share my reasoning. First of all, we want // Old code
const float text_width = g.FontSize + (label_size.x > 0.0f ? label_size.x + padding.x * 2 : 0.0f); // Include collapsing arrow
layout_width = text_width; I tried two approaches: // New 1
const float text_width = g.FontSize + label_size.x + padding.x * 2;
layout_width = text_width; New 1 embeds the arrow padding. It's standard and doesn't look hacky. But it breaks every // New 2
const float text_width = g.FontSize + label_size.x + padding.x * 2;
layout_width = text_width + (label_size.x > 0.0f ? 0.0f : -style.ItemSpacing.x); New 2 tries to undo the effect of So I went for New 1. Which is more breaking, but ultimately this idiom is not used by everyone. There's an additional quirk which is that interact_bb is altered differently when label_size.x but I think it does make sense as when you use an empty label you are likely to add an immediately neighbor item, and if that item is interactive (a button) you need to avoid tree node overlapping it. Either way as mentioned users of TreeNode("") are likely to use PS: There are no matches for neither |
Added a test ocornut/imgui_test_engine@fac000b Closing as solved! |
🥳 Glad I was able to help! ImGUI is such a cool project and I love improving the tools I use |
Version/Branch of Dear ImGui:
v1.90.1 WIP + docking
Back-ends:
N/A
Compiler, OS:
Windows
Full config/build information:
Details:
What's the Proper way to render custom text or custom items in the body of a TreeNode :
I am creating a general Tree style console application and want to be able to do more then the standard TreeNode label that TreeNode provides.
For example id like to be able to have the Arrow, Blue text, And then a white colon
The current solution is
But there's one fairly glaring issue with this. Its that the Text "SubObject" Is far too close to the Arrow. When i add Text into the Label the spacing looks correct. But for some reason things behave slightly differently when you pass in a blank label. I'm aware i can probably just manually set the X Cursor position to be the start of the line + ImGui::GetTreeNodeToLabelSpacing(), Or find the magic value to indent by. But I am just wondering if there is a cleaner way to go about it.
Screenshots/Video:
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: