From 7109f32f963564c633abb7448aa250a5844b2b7c Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 3 Nov 2022 16:25:15 +0100 Subject: [PATCH] Internals: tidying up and stripping more of focus scope code. --- imgui.cpp | 26 ++++++++------------------ imgui_internal.h | 14 ++------------ 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index ded31fa7..d7609dbc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6329,9 +6329,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->ParentWindowInBeginStack = parent_window_in_stack; } - // Add to focus scope stack - inherited by default by child windows from parent, reset by regular window - //if (window == window->RootWindow && (window->Flags & ImGuiWindowFlags_ChildMenu) == 0) - PushFocusScope(window->ID); + // Add to focus scope stack + PushFocusScope(window->ID); window->NavRootFocusScopeId = g.CurrentFocusScopeId; g.CurrentWindow = NULL; @@ -6942,8 +6941,7 @@ void ImGui::End() if (window->DC.CurrentColumns) EndColumns(); PopClipRect(); // Inner window clip rectangle - //if (window == window->RootWindow && (window->Flags & ImGuiWindowFlags_ChildMenu) == 0) - PopFocusScope(); + PopFocusScope(); // Stop logging if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging @@ -7624,24 +7622,16 @@ void ImGui::ActivateItem(ImGuiID id) void ImGui::PushFocusScope(ImGuiID id) { ImGuiContext& g = *GImGui; - if (g.FocusScopeStackLocked > 0) - return; - ImGuiFocusScope scope; - scope.FocusScopeId = id; - scope.Window = g.CurrentWindow; - g.FocusScopeStack.push_back(scope); - g.CurrentFocusScopeId = scope.FocusScopeId; + g.FocusScopeStack.push_back(id); + g.CurrentFocusScopeId = id; } void ImGui::PopFocusScope() { ImGuiContext& g = *GImGui; - if (g.FocusScopeStackLocked > 0) - return; IM_ASSERT(g.FocusScopeStack.Size > 0); // Too many PopFocusScope() ? - IM_ASSERT(g.FocusScopeStack.back().Window == g.CurrentWindow); // Mismatched pop location? g.FocusScopeStack.pop_back(); - g.CurrentFocusScopeId = g.FocusScopeStack.Size ? g.FocusScopeStack.back().FocusScopeId : 0; + g.CurrentFocusScopeId = g.FocusScopeStack.Size ? g.FocusScopeStack.back() : 0; } // Note: this will likely be called ActivateItem() once we rework our Focus/Activation system! @@ -10750,7 +10740,7 @@ void ImGui::NavUpdateCreateMoveRequest() inner_rect_rel.Min.y = clamp_y ? (inner_rect_rel.Min.y + pad_y) : -FLT_MAX; inner_rect_rel.Max.y = clamp_y ? (inner_rect_rel.Max.y - pad_y) : +FLT_MAX; window->NavRectRel[g.NavLayer].ClipWithFull(inner_rect_rel); - g.NavId = /*g.NavFocusScopeId =*/ 0; + g.NavId = 0; } } @@ -10933,7 +10923,7 @@ static void ImGui::NavUpdateCancelRequest() // Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow))) g.NavWindow->NavLastIds[0] = 0; - g.NavId = /*g.NavFocusScopeId =*/ 0; + g.NavId = 0; } } diff --git a/imgui_internal.h b/imgui_internal.h index 8aeda428..c5ddac76 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1388,14 +1388,6 @@ struct ImGuiNavItemData void Clear() { Window = NULL; ID = FocusScopeId = 0; InFlags = 0; DistBox = DistCenter = DistAxial = FLT_MAX; } }; -struct ImGuiFocusScope -{ - ImGuiID FocusScopeId; - ImGuiWindow* Window; - - ImGuiFocusScope() { memset(this, 0, sizeof(*this)); } -}; - //----------------------------------------------------------------------------- // [SECTION] Columns support //----------------------------------------------------------------------------- @@ -1696,7 +1688,7 @@ struct ImGuiContext #endif // Next window/item data - ImGuiID CurrentFocusScopeId; // == g.FocusScopeStack.back().FocusScopeId + ImGuiID CurrentFocusScopeId; // == g.FocusScopeStack.back() ImGuiItemFlags CurrentItemFlags; // == g.ItemFlagsStack.back() ImGuiNextItemData NextItemData; // Storage for SetNextItem** functions ImGuiLastItemData LastItemData; // Storage for last submitted item (setup by ItemAdd) @@ -1706,13 +1698,12 @@ struct ImGuiContext 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 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) int BeginMenuCount; - int FocusScopeStackLocked; // Prevent PushFocusScope()/PopFocusScope() // Viewports ImVector Viewports; // Active viewports (Size==1 in 'master' branch). Each viewports hold their copy of ImDrawData. @@ -1950,7 +1941,6 @@ struct ImGuiContext CurrentFocusScopeId = 0; CurrentItemFlags = ImGuiItemFlags_None; BeginMenuCount = 0; - FocusScopeStackLocked = 0; NavWindow = NULL; NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavActivateInputId = 0;