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
image image

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

Most upvoted comments

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. Selectable calls ItemSize with the size of the text label (or its width, at least), and ItemAdd with the size of its entire bounding box. By default its bounding box expands up to window->WorkRect.Max.x. Everything’s good so far.

Earlier version of EndGroup was getting the group size from DC.CursorMaxPos, which is updated by ItemSize. The current version also mixes in LastItemData.Rect.Max, which is updated by ItemAdd. 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 uses ImGuiSelectableFlags_SpanAllColumns.

The growth is caused by the “half-space padding” that the selectable does: by default it adds half of ItemSpacing on all sides, which, combined with window auto-sizing, shifts window->WorkRect.Max.x by 4 pixels every frame.

As a bottomline, I’d say LastItemData.Rect.Max should not be used to compute the group size.