From 854e21d4b4c8ce3d65cb0e38754458516904743c Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 31 May 2024 18:23:47 +0200 Subject: [PATCH] Disabled: move field to ImGuiWindowStackData. (#7640) Amend f953ebf --- imgui.cpp | 16 ++++++++-------- imgui_internal.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cbcf8278a..22333b70f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6562,6 +6562,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window_stack_data.Window = window; window_stack_data.ParentLastItemDataBackup = g.LastItemData; window_stack_data.StackSizesOnBegin.SetToContextState(&g); + window_stack_data.DisabledOverrideReenable = (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0; g.CurrentWindowStack.push_back(window_stack_data); if (flags & ImGuiWindowFlags_ChildMenu) g.BeginMenuDepth++; @@ -6649,9 +6650,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) UpdateWindowSkipRefresh(window); // Nested root windows (typically tooltips) override disabled state - if (window->RootWindow == window) - if ((window->DC.BackupItemDisabled = (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0)) - BeginDisabledOverrideReenable(); + if (window_stack_data.DisabledOverrideReenable && window->RootWindow == window) + BeginDisabledOverrideReenable(); // We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow() g.CurrentWindow = NULL; @@ -7252,7 +7252,7 @@ void ImGui::End() IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size > 1, "Calling End() too many times!"); return; } - IM_ASSERT(g.CurrentWindowStack.Size > 0); + ImGuiWindowStackData& window_stack_data = g.CurrentWindowStack.back(); // Error checking: verify that user doesn't directly call End() on a child window. if (window->Flags & ImGuiWindowFlags_ChildWindow) @@ -7264,7 +7264,7 @@ void ImGui::End() if (!window->SkipRefresh) PopClipRect(); // Inner window clip rectangle PopFocusScope(); - if (window->RootWindow == window && window->DC.BackupItemDisabled) + if (window_stack_data.DisabledOverrideReenable && window->RootWindow == window) EndDisabledOverrideReenable(); if (window->SkipRefresh) @@ -7281,12 +7281,12 @@ void ImGui::End() ErrorCheckUsingSetCursorPosToExtendParentBoundaries(); // Pop from window stack - g.LastItemData = g.CurrentWindowStack.back().ParentLastItemDataBackup; + g.LastItemData = window_stack_data.ParentLastItemDataBackup; if (window->Flags & ImGuiWindowFlags_ChildMenu) g.BeginMenuDepth--; if (window->Flags & ImGuiWindowFlags_Popup) g.BeginPopupStack.pop_back(); - g.CurrentWindowStack.back().StackSizesOnBegin.CompareWithContextState(&g); + window_stack_data.StackSizesOnBegin.CompareWithContextState(&g); g.CurrentWindowStack.pop_back(); SetCurrentWindow(g.CurrentWindowStack.Size == 0 ? NULL : g.CurrentWindowStack.back().Window); } @@ -10030,7 +10030,7 @@ void ImGui::ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, vo else { EndDisabledOverrideReenable(); - window->DC.BackupItemDisabled = false; + g.CurrentWindowStack.back().DisabledOverrideReenable = false; } } while (g.ColorStack.Size > stack_sizes->SizeOfColorStack) diff --git a/imgui_internal.h b/imgui_internal.h index 228a0f7e2..fbc3fe41d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1243,7 +1243,8 @@ struct ImGuiWindowStackData { ImGuiWindow* Window; ImGuiLastItemData ParentLastItemDataBackup; - ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting + ImGuiStackSizes StackSizesOnBegin; // Store size of various stacks for asserting + bool DisabledOverrideReenable; // Non-child window override disabled flag }; struct ImGuiShrinkWidthItem @@ -2472,7 +2473,6 @@ struct IMGUI_API ImGuiWindowTempData bool NavWindowHasScrollY; // Set per window when scrolling can be used (== ScrollMax.y > 0.0f) // Miscellaneous - bool BackupItemDisabled; // Non-child window override disabled flag bool MenuBarAppending; // FIXME: Remove this ImVec2 MenuBarOffset; // MenuBarOffset.x is sort of equivalent of a per-layer CursorPos.x, saved/restored as we switch to the menu bar. The only situation when MenuBarOffset.y is > 0 if when (SafeAreaPadding.y > FramePadding.y), often used on TVs. ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items measurement