You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SetNextWindowSize() on single axis doesn't perform auto-fit calculation correctly #9060
I think window's size calculation should take account of whether the window uses scrollbar. Take the screenshots for example, both auto-resized windows (ImGuiWindowFlags_AlwaysAutoResize) and resizable windows (auto-fitting) are affected by this.
Screenshots/Video:
Auto-resized window: (| of the longest string becomes hidden by the scrollbar)
Resizable window: (| of the longest string becomes hidden after auto-fitting)
changed the title [-]Window-size calculation should take account of scrollbar[/-][+]SetNextWindowSize() on single axis + _AlwaysAutoResize conflict[/+]on Nov 10, 2025
changed the title [-]SetNextWindowSize() on single axis + _AlwaysAutoResize conflict[/-][+]SetNextWindowSize() on single axis doesn't perform auto-fit calculation correctly[/+]on Nov 10, 2025
Window-size calculation should take account of scrollbar[/-]
In most cases it does, but it seems like ImGui::SetNextWindowSize({ 0,ImGui::GetTextLineHeightWithSpacing() * 10 }); actually breaks the logic for auto-fitting indeed.
Right, this correspond to this FIXME in UpdateWindowManualResize():
// Double-clicking bottom or right border auto-fit on this axis// FIXME: CalcWindowAutoFitSize() doesn't take into account that only one side may be auto-fit when calculating scrollbars.if (border_n == 1 || border_n == 3) // Right and bottom border
{
size_target[axis] = CalcWindowSizeAfterConstraint(window, size_auto_fit)[axis];
ret_auto_fit_mask |= (1 << axis);
hovered = held = false; // So border doesn't show highlighted at new position
}
Since both uses of size_auto_fit are on specific actions, we could remove this parameter and instead redesign CalcWindowAutoFitSize() to support single-axis mode, and call this in UpdateWindowManualResize().
Activity
[-]Window-size calculation should take account of scrollbar[/-][+]SetNextWindowSize() on single axis + _AlwaysAutoResize conflict[/+][-]SetNextWindowSize() on single axis + _AlwaysAutoResize conflict[/-][+]SetNextWindowSize() on single axis doesn't perform auto-fit calculation correctly[/+]ocornut commentedon Nov 10, 2025
In most cases it does, but it seems like
ImGui::SetNextWindowSize({ 0,ImGui::GetTextLineHeightWithSpacing() * 10 });actually breaks the logic for auto-fitting indeed.Note that this works:
if (fix_height) { float height = ImGui::GetTextLineHeightWithSpacing() * 10; -- ImGui::SetNextWindowSize({ 0, height }); ++ ImGui::SetNextWindowSizeConstraints(ImVec2(0.0f, height), ImVec2(FLT_MAX, height)); }achabense commentedon Nov 10, 2025
Thanks! Changing
SetNextWindowSizetoSetNextWindowSizeConstraintssolves my original problem.So the second screenshot (auto-fitting) seems a separate problem. Initially I thought they are the same one.
This is enough to reproduce the second screenshot. (When the window has vertical scrollbar and auto-fit horizontally.)
{ if (ImGui::Begin("Auto", 0, ImGuiWindowFlags_NoSavedSettings)) { for (const int n : {1, 5, 2, 3, 9, 6, 3, 1}) { ImGui::TextUnformatted((std::string(n + 10, 'a') + "|").c_str()); } } ImGui::End(); }ocornut commentedon Nov 10, 2025
Right, this correspond to this FIXME in
UpdateWindowManualResize():Since both uses of
size_auto_fitare on specific actions, we could remove this parameter and instead redesignCalcWindowAutoFitSize()to support single-axis mode, and call this inUpdateWindowManualResize().ocornut commentedon Nov 10, 2025
I believe this should fix the second issue, and it's passing imgui_test_suite, and can be foundation to fix the first issue too.
But I'll work on adding more tests first.
Windows: fixed single-axis auto-sizing (via double-clicking a border)…
ocornut commentedon Nov 10, 2025
ocornut commentedon Nov 11, 2025
Note that 7537ba2 actually removed the need for the hack added in 29439bd and tested by
"window_child_resize". (#1710)Windows: reorganize auto-fitting code blocks in Begin(), aimed to hav…
Windows: reorganize auto-fitting code blocks in Begin(), step 2.
Windows: programmatic auto-sizing on a single axis also apply proper …
Windows: CalcWindowAutoFitSize() remove child-specific hack added by 2…
ocornut commentedon Nov 11, 2025
Both cases should be fixed now.
Because window sizing code is extremely sensitive I zealously split the changes in many commits.
It's not actually many changes but out of experience this is generally going to be useful if I need to come back to this later.
Now bracing for impact....
Windows: fixed single-axis auto-sizing (via double-clicking a border)…
Windows: reorganize auto-fitting code blocks in Begin(), aimed to hav…
Windows: reorganize auto-fitting code blocks in Begin(), step 2.
Windows: programmatic auto-sizing on a single axis also apply proper …
Windows: CalcWindowAutoFitSize() remove child-specific hack added by 2…