From 0fc8ba7e475b60fc2a37478901397f27fee122fa Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Tue, 28 Apr 2026 14:39:43 +0200 Subject: [PATCH] StackLayout: don't inflate measured_size when layout has no springs EndLayout() inflates `layout->CurrentSize` on the main axis up to the parent layout's CurrentSize, then assigns `measured_size = CurrentSize` and emits `ItemAdd(StartPos, StartPos + measured_size)`. The inflation is needed only so that BalanceLayoutSprings() has `free_space = CurrentSize - MinimumSize` to distribute among springs. When the layout has no springs, BalanceLayoutSprings() is a no-op, no item is moved, and the inflated `measured_size` describes empty space that nothing draws into. The inflated `measured_size` is then planted into `g.LastItemData.Rect` by the subsequent ItemAdd. A surrounding ImGui::BeginGroup/EndGroup pair (or anything else that consults LastItemData.Rect.Max for an enclosing bounding box) then ImMaxes that stale, larger-than-real value into its own bbox. The group never shrinks on the inner layout's main axis after the layout has been larger in any prior frame. Gating the inflation on HasAnyNonZeroSpring(*layout) keeps the spring-using case identical to today's behavior and removes the leak in every other case. The inflated CurrentSize is reset every frame in BeginLayout(), so nothing persists across frames. --- imgui_stacklayout.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imgui_stacklayout.cpp b/imgui_stacklayout.cpp index 12c9779547b5..f161ce7bb182 100644 --- a/imgui_stacklayout.cpp +++ b/imgui_stacklayout.cpp @@ -539,7 +539,8 @@ static void ImGui::EndLayout(ImGuiLayoutType type) layout->CurrentSize = new_size; ImVec2 measured_size = new_size; - if ((auto_width || auto_height) && layout->Parent) + // Inflate to parent size only when there are springs that need the free space. + if ((auto_width || auto_height) && layout->Parent && HasAnyNonZeroSpring(*layout)) { if (layout->Type == ImGuiLayoutType_Horizontal && auto_width && layout->Parent->CurrentSize.x > 0) layout->CurrentSize.x = layout->Parent->CurrentSize.x;