From fa2e5710acbc55c16ef01c52c81b63bae895cf15 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 6 Sep 2023 12:39:39 +0200 Subject: [PATCH] MenuBar: Fixed an issue where layouting an item in the menu-bar would erroneously egister contents size. (#6789) In dire need of removing BeginGroup()/EndGroup() from menu-bar code, fo r sanity. --- docs/CHANGELOG.txt | 3 +++ imgui_internal.h | 16 ++++++++-------- imgui_widgets.cpp | 10 ++++++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 76feb98f..2717fc94 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -47,6 +47,9 @@ Other changes: - InputTextMultiline: Fixed a crash pressing Down on last empty line of a multiline buffer. (regression from 1.89.2, only happened in some states). (#6783, #6000) - BeginListBox(): Fixed not consuming SetNextWindowXXX data when returning false. +- MenuBar: Fixed an issue where layouting an item in the menu-bar would erroneously + register contents size in a way that would affect the scrolling layer. + Was most often noticable when using an horizontal scrollbar. (#6789) - Backends: GLFW: Clear emscripten's MouseWheel callback before shutdown. (#6790, #6096, #4019) [@halx99] diff --git a/imgui_internal.h b/imgui_internal.h index 7f6dbe35..65201ca6 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1868,14 +1868,14 @@ struct ImGuiContext ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions // Shared stacks - ImVector ColorStack; // Stack for PushStyleColor()/PopStyleColor() - inherited by Begin() - ImVector StyleVarStack; // Stack for PushStyleVar()/PopStyleVar() - inherited by Begin() - ImVector FontStack; // Stack for PushFont()/PopFont() - inherited by Begin() - ImVector FocusScopeStack; // Stack for PushFocusScope()/PopFocusScope() - inherited by BeginChild(), pushed into by Begin() - ImVectorItemFlagsStack; // Stack for PushItemFlag()/PopItemFlag() - inherited by Begin() - ImVectorGroupStack; // Stack for BeginGroup()/EndGroup() - not inherited by Begin() - ImVectorOpenPopupStack; // Which popups are open (persistent) - ImVectorBeginPopupStack; // Which level of BeginPopup() we are in (reset every frame) + ImVector ColorStack; // Stack for PushStyleColor()/PopStyleColor() - inherited by Begin() + ImVector StyleVarStack; // Stack for PushStyleVar()/PopStyleVar() - inherited by Begin() + ImVector FontStack; // Stack for PushFont()/PopFont() - inherited by Begin() + ImVector FocusScopeStack; // Stack for PushFocusScope()/PopFocusScope() - inherited by BeginChild(), pushed into by Begin() + ImVector ItemFlagsStack; // Stack for PushItemFlag()/PopItemFlag() - inherited by Begin() + ImVector GroupStack; // Stack for BeginGroup()/EndGroup() - not inherited by Begin() + ImVector OpenPopupStack; // Which popups are open (persistent) + ImVector BeginPopupStack; // Which level of BeginPopup() we are in (reset every frame) ImVector NavTreeNodeStack; // Stack for TreeNode() when a NavLeft requested is emitted. int BeginMenuCount; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d63a629f..e4ade8c7 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7035,12 +7035,18 @@ void ImGui::EndMenuBar() PopClipRect(); PopID(); window->DC.MenuBarOffset.x = window->DC.CursorPos.x - window->Pos.x; // Save horizontal position so next append can reuse it. This is kinda equivalent to a per-layer CursorPos. - g.GroupStack.back().EmitItem = false; - EndGroup(); // Restore position on layer 0 + + // FIXME: Extremely confusing, cleanup by (a) working on WorkRect stack system (b) not using a Group confusingly here. + ImGuiGroupData& group_data = g.GroupStack.back(); + group_data.EmitItem = false; + ImVec2 restore_cursor_max_pos = group_data.BackupCursorMaxPos; + window->DC.IdealMaxPos.x = ImMax(window->DC.IdealMaxPos.x, window->DC.CursorMaxPos.x - window->Scroll.x); // Convert ideal extents for scrolling layer equivalent. + EndGroup(); // Restore position on layer 0 // FIXME: Misleading to use a group for that backup/restore window->DC.LayoutType = ImGuiLayoutType_Vertical; window->DC.IsSameLine = false; window->DC.NavLayerCurrent = ImGuiNavLayer_Main; window->DC.MenuBarAppending = false; + window->DC.CursorMaxPos = restore_cursor_max_pos; } // Important: calling order matters!