Comments (8)
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 ImGui::TreeNodeBehavior()
. Doable, but not ideal in case this implementation ever changes.
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.
from imgui.
It seems like a bug to me that TreeNode("##EmptyLabel")
doesn't allow for that by default.
from imgui.
I'm sincerely surprised this has not been submitted before.
By sheer accident, with the default style settings if you do what you did (TreeNode("") + SameLine()
) it looks correct, but it's only accidentally because ItemSpacing.x = FramePadding.x * 2 with default settings. This is the reason I haven't noticed that before :(
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 (label_size.x > 0.0f)
test. We are talking ancient times (#282) but that specific change wasn't exactly the main point of the commit.
I'll push a fix soon.
from imgui.
:(
Well that's the beauty of open source, Eventually someone's gonna use every line of code at one point or another so stuff like this will get caught. Glad I could help out and make this project just a little bit better.
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 TreeNodeBehavior
so i can get more finetune control on the bounding boxes
from imgui.
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 TreeNodeBehavior so i can get more finetune control on the bounding boxes
You probably want to use ImGuiTreeNodeFlags_SpanAvailWidth
here, and possibly ImGuiTreeNodeFlags_AllowOverlap
if you also need to add e.g. SmallButton()
on the same line.
from imgui.
I've pushed a fix 361432a however this is a breaking fix, and I need to share my reasoning.
First of all, we want TreeNode("Hello"), SameLine(), Text("World")
to be unaltered since this is a frequent pattern and it works. That's for sure.
// 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 TreeNode(""), SameLine()
use which needs to be changed into TreeNode(), SameLine(0,0)
.
Pros: it's fairly consistent.
Pros: it visibly breaks regardless of styling value: issue not hidden in default style.
Cons: it visibly breaks regardless of styling value: issue not hidden in default style. :)
// 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 SameLine()
.
Pros: it breaks less case.
Cons: it's less consistent, it'sweird and I've learned enough about the troubles of selectable and treenode doing inconsistent hacks that I would prefer to stay clear of them.
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 ImGuiTreeNodeFlags_SpanAvailWidth
and ImGuiTreeNodeFlags_AllowOverlap
anyhow.
PS: There are no matches for neither TreeNode("")
and TreeNode("##xxx");
in the demo code.
from imgui.
Added a test ocornut/imgui_test_engine@fac000b
Closing as solved!
from imgui.
🥳 Glad I was able to help! ImGUI is such a cool project and I love improving the tools I use
from imgui.
Related Issues (20)
- Scale to window maintaining aspect ratio, but Viewport won't center HOT 2
- Please help me to clarify the concepts of some specific terms HOT 2
- WebGPU ImGui::Image not accepts different texture formats HOT 3
- InputText CTRL+V paste fails if text is too long HOT 4
- for some reason when i try to change the color of my text and try to do pop style color it crashed? HOT 3
- Why does ImGui tables insert extra ID into the id path of the child widgets? HOT 1
- Emscripten build runtime error: Unable to preventDefault inside passive event listener HOT 5
- getting tightest possible horizontal spacing HOT 7
- #7595 turned into an issue related to fonts loading problem after upgrade (ImGui/SDL3/Vulkan)
- Color too dark custom checkbox color fill HOT 3
- No horizontal scrollbar in a window when calling SetNextWindowContentSize with size larger than the screen HOT 6
- Plugin architecture in imgui(C++)? HOT 3
- Misbehaving GUI when i through libigl to use imgui HOT 2
- DXGI warning with DX11 backend about `DXGI_SWAP_EFFECT_DISCARD` HOT 4
- Transparent issue HOT 3
- ImGui Dockspace not working when viewports are enabled HOT 11
- Tabbar containing dockspace HOT 8
- How to dock a window to the size programmatically wthout taking the whole space HOT 3
- Memory leak when rendering with DX11 in C++ HOT 13
- How to display the same texture with different scale modes?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgui.