imgui: `BeginGroup`/`EndGroup` with table inside reports incorrect item size
Version/Branch of Dear ImGui:
Version 1.90.6 WIP (r19053), Branch: master
Back-ends:
imgui_impl_win32.cpp + imgui_impl_dx11.cpp
Compiler, OS:
Windows 11, MSVC 2022, x64
Full config/build information:
Dear ImGui 1.90.6 WIP (19053)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1939
define: _MSVC_LANG=201402
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000000
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
HasMouseCursors
HasSetMousePos
RendererHasVtxOffset
--------------------------------
io.Fonts: 2 fonts, Flags: 0x00000000, TexSize: 1024,1024
io.DisplaySize: 1905.33,987.33
io.DisplayFramebufferScale: 1.50,1.50
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00
Details:
My understanding is that groups should surround containing widgets, which isn’t the case with tables.
Table surrounded by BeginGroup/EndGroup appears to be measured incorrectly.
Problem can be reproduced simply by resizing Test2 window. Green rect is expected to cover whole table.
Push shift key to enable workaround, which place 0 size dummy widget at the same line as table.
Digging into the code, table OuterRect seems to be “stuck” on minimum size. At the moment I cannot tell if this is an desired behavior or not.
Screenshots/Video:
| Current | Expected |
|---|---|
Minimal, Complete and Verifiable Example code:
ImGui::Begin("Test2");
ImGui::BeginGroup();
if (ImGui::BeginTable("table2", 2))
{
ImGui::TableNextColumn();
ImGui::Text("Thing 1");
ImGui::TableNextColumn();
ImGui::Text("Thing 2");
ImGui::EndTable();
}
if (ImGui::GetIO().KeyShift)
{
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
ImGui::SameLine(0.0f, 0.0f);
ImGui::Dummy(ImVec2(0.0f, 0.0f));
ImGui::PopStyleVar();
}
ImGui::EndGroup();
ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(0, 255, 0, 64), 4.0f);
ImGui::End();
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 16 (7 by maintainers)
Commits related to this issue
- Groups, Tables: fixed EndGroup() failing to correctly capture current table occupied size. (#7543) See "layout_group_endtable" test. — committed to ocornut/imgui by ocornut 2 years ago
- TestSuite: added "layout_group_endtable" https://github.com/ocornut/imgui/issues/7543 — committed to ocornut/imgui_test_engine by ocornut 2 years ago
- Ocornut master (24/07) (#4) * Version 1.90.8 * Version 1.90.9 WIP * Internals: renamed HoveredIdDisabled to HoveredIdIsDisabled for consistency. * Examples: GLFW+Vulkan: handle swap chain re... — committed to Ciachociech/imgui by Ciachociech 2 years ago
Yet another DearPyGui user has just reported the regression I mentioned in earlier comments - this time on a group consisting of a button,
SameLine, and a selectable.@ocornut any chance for this ticket to get a bit of your attention? I think it’s 5th or 6th time I see it reported in the DearPyGui community.
Not intentional, will investigate a solution (I don’t think clearing LastItemData in BeginGroup() would work). Thanks!
So here’s the gotcha.
SelectablecallsItemSizewith the size of the text label (or its width, at least), andItemAddwith the size of its entire bounding box. By default its bounding box expands up towindow->WorkRect.Max.x. Everything’s good so far.Earlier version of
EndGroupwas getting the group size fromDC.CursorMaxPos, which is updated byItemSize. The current version also mixes inLastItemData.Rect.Max, which is updated byItemAdd. Thus, the old version of the group only covered the text label of the selectable, whereas the new version covers its entire bounding box, which itself seems to be wrong e.g. when the selectable is inside a table and usesImGuiSelectableFlags_SpanAllColumns.The growth is caused by the “half-space padding” that the selectable does: by default it adds half of
ItemSpacingon all sides, which, combined with window auto-sizing, shiftswindow->WorkRect.Max.xby 4 pixels every frame.As a bottomline, I’d say
LastItemData.Rect.Maxshould not be used to compute the group size.