-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Wrong width of collapsing header or selectable when added in side by side childs or table #6170
Comments
Hello, You mention using table API which should be the natural way of doing this two-columns layout, yet none of your example use the By default It naturally cannot be done if the host window has no padding (& no initial indent). This is what you see in Test 4 and what you would also see in Test 2 if you altered style so that Test 3 is "correct" in the sense that:
The way to do this if you need to use BeginChild() to split that window in two may be to use a child with zero padding, then inside CollapsingHeader() followed by an Indent() call. However, as mentioned, it may ultimately be different with tables. |
Thank you very much for your reactivity! Yes, I did not had the Table example, sorry. Here it is :
This produces the same result as the one presented on figure "Test 4". To sum up your response : before the call to the child (but after the call to Begin(xxx)), set |
There are many tangled factors here. Sorry this is going to be involved :) First of all, in case it isn't evident, in the case of BeginChild() (or BeginTable() with scrolling enabled, which is essentially a child) we need to draw within the boundary of the child window mostly for performances reasons (more on that later). So if the window has no padding and we start submitting item from window relative x=0, we can't extend to the left. We could technically push clip rects but it would be too costly if done per item and would generate draw calls. We could also allocate a specific layer but it's involved (but not impossible). In the case of table we have a specialized system/channel to optimally honor features such as else if (span_all_columns && g.CurrentTable)
TablePushBackgroundChannel(); So a Selectable can cover multiple rows. Another issue specific with if (display_frame)
{
// Framed header expand a little outside the default padding, to the edge of InnerClipRect
// (FIXME: May remove this at some point and make InnerClipRect align with WindowPadding.x instead of WindowPadding.x*0.5f)
frame_bb.Min.x -= IM_FLOOR(window->WindowPadding.x * 0.5f - 1.0f);
frame_bb.Max.x += IM_FLOOR(window->WindowPadding.x * 0.5f);
} This has been the case since prehistoric times: 824cf5a added the latch in
if (display_frame && !g.IO.KeyShift)
{
// Framed header expand a little outside the default padding, to the edge of InnerClipRect
// (FIXME: May remove this at some point and make InnerClipRect align with WindowPadding.x instead of WindowPadding.x*0.5f)
frame_bb.Min.x -= IM_FLOOR(style.WindowPadding.x * 0.5f - 1.0f);
frame_bb.Max.x += IM_FLOOR(style.WindowPadding.x * 0.5f);
} And press SHIFT to compare.
|
I tried what you suggested @ocornut and here are the results. First, if I do not press the SHIFT key, we have If I press the SHIFT key, then we have The headers are perfectly aligned with the rest of the elements and the results are consistent in that sense that whatever the approach I consider, the visual output feels the same. |
@ocornut in #6173, you said: "TL;DR; you could add window padding to your child" I am not sure how you do this exactly. I tried: auto windowPadding = ImGui::GetStyle().WindowPadding;
if(ImGui::BeginChild("Content"))
{
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, windowPadding);
ImGui::Selectable("select1", true);
ImGui::Selectable("select2", true);
ImGui::PopStyleVar();
} and that doesn't do anything |
WindowPadding is applied at the time of Begin()/BeginChild(). |
This is being discussed in details in this topic. There's no single simple answer. |
Disabling padding and adding the corresponding |
Version/Branch of Dear ImGui:
Version: 1.89.2
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_vulkan.cpp + imgui_impl_glfw.cpp
Compiler: clang
Operating System: MacOS 12.6
My Issue/Question:
I would like to have two panels side by side. Each panel has at least one CollapsingHeader element. This is very easy to do, using the BeginChild API or using a table. However, the size of the CollapsingHeader is not consistent, whatever the approach I tried. You will find below one working example based using a BeginChild approach and a picture giving the results I obtained.
I would like to get something very similar to the results presented on the window "Test 4" but with the correct width of the CollapsingHeader elements (similar to the one on window Test 2) and presenting an indent between the CollapsingHeader and the content below (see Test 2), plus with the correct padding.
I tried something with the
ImGuiWindowFlags_AlwaysUseWindowPadding
flag, but in that case the padding is too important (see picture Test 3).What am I doing wrong or missing?
Screenshots/Video
Standalone, minimal, complete and verifiable example:
The text was updated successfully, but these errors were encountered: