Internals: add window to FocusScopeStack. (#6798)

This commit is contained in:
ocornut 2024-01-15 11:44:21 +01:00
parent 2156db7a07
commit 4b20a0217e
2 changed files with 30 additions and 17 deletions

View File

@ -3075,7 +3075,7 @@ void ImGui::PopStyleColor(int count)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (g.ColorStack.Size < count) if (g.ColorStack.Size < count)
{ {
IM_ASSERT_USER_ERROR(g.ColorStack.Size > count, "Calling PopStyleColor() too many times: stack underflow."); IM_ASSERT_USER_ERROR(g.ColorStack.Size > count, "Calling PopStyleColor() too many times!");
count = g.ColorStack.Size; count = g.ColorStack.Size;
} }
while (count > 0) while (count > 0)
@ -3138,7 +3138,7 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
*pvar = val; *pvar = val;
return; return;
} }
IM_ASSERT_USER_ERROR(0, "Called PushStyleVar() variant with wrong type!"); IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
} }
void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val) void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
@ -3152,7 +3152,7 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
*pvar = val; *pvar = val;
return; return;
} }
IM_ASSERT_USER_ERROR(0, "Called PushStyleVar() variant with wrong type!"); IM_ASSERT_USER_ERROR(0, "Calling PushStyleVar() variant with wrong type!");
} }
void ImGui::PopStyleVar(int count) void ImGui::PopStyleVar(int count)
@ -3160,7 +3160,7 @@ void ImGui::PopStyleVar(int count)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (g.StyleVarStack.Size < count) if (g.StyleVarStack.Size < count)
{ {
IM_ASSERT_USER_ERROR(g.StyleVarStack.Size > count, "Calling PopStyleVar() too many times: stack underflow."); IM_ASSERT_USER_ERROR(g.StyleVarStack.Size > count, "Calling PopStyleVar() too many times!");
count = g.StyleVarStack.Size; count = g.StyleVarStack.Size;
} }
while (count > 0) while (count > 0)
@ -7798,16 +7798,23 @@ void ImGui::SetWindowFontScale(float scale)
void ImGui::PushFocusScope(ImGuiID id) void ImGui::PushFocusScope(ImGuiID id)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
g.FocusScopeStack.push_back(id); ImGuiFocusScopeData data;
data.ID = id;
data.WindowID = g.CurrentWindow->ID;
g.FocusScopeStack.push_back(data);
g.CurrentFocusScopeId = id; g.CurrentFocusScopeId = id;
} }
void ImGui::PopFocusScope() void ImGui::PopFocusScope()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
IM_ASSERT(g.FocusScopeStack.Size > 0); // Too many PopFocusScope() ? if (g.FocusScopeStack.Size == 0)
{
IM_ASSERT_USER_ERROR(g.FocusScopeStack.Size > 0, "Calling PopFocusScope() too many times!");
return;
}
g.FocusScopeStack.pop_back(); g.FocusScopeStack.pop_back();
g.CurrentFocusScopeId = g.FocusScopeStack.Size ? g.FocusScopeStack.back() : 0; g.CurrentFocusScopeId = g.FocusScopeStack.Size ? g.FocusScopeStack.back().ID : 0;
} }
// Focus = move navigation cursor, set scrolling, set focus window. // Focus = move navigation cursor, set scrolling, set focus window.

View File

@ -1571,6 +1571,12 @@ struct ImGuiNavItemData
void Clear() { Window = NULL; ID = FocusScopeId = 0; InFlags = 0; SelectionUserData = -1; DistBox = DistCenter = DistAxial = FLT_MAX; } void Clear() { Window = NULL; ID = FocusScopeId = 0; InFlags = 0; SelectionUserData = -1; DistBox = DistCenter = DistAxial = FLT_MAX; }
}; };
struct ImGuiFocusScopeData
{
ImGuiID ID;
ImGuiID WindowID;
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] Typing-select support // [SECTION] Typing-select support
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -1981,7 +1987,7 @@ struct ImGuiContext
ImVector<ImGuiColorMod> ColorStack; // Stack for PushStyleColor()/PopStyleColor() - inherited by Begin() ImVector<ImGuiColorMod> ColorStack; // Stack for PushStyleColor()/PopStyleColor() - inherited by Begin()
ImVector<ImGuiStyleMod> StyleVarStack; // Stack for PushStyleVar()/PopStyleVar() - inherited by Begin() ImVector<ImGuiStyleMod> StyleVarStack; // Stack for PushStyleVar()/PopStyleVar() - inherited by Begin()
ImVector<ImFont*> FontStack; // Stack for PushFont()/PopFont() - inherited by Begin() ImVector<ImFont*> FontStack; // Stack for PushFont()/PopFont() - inherited by Begin()
ImVector<ImGuiID> FocusScopeStack; // Stack for PushFocusScope()/PopFocusScope() - inherited by BeginChild(), pushed into by Begin() ImVector<ImGuiFocusScopeData> FocusScopeStack; // Stack for PushFocusScope()/PopFocusScope() - inherited by BeginChild(), pushed into by Begin()
ImVector<ImGuiItemFlags> ItemFlagsStack; // Stack for PushItemFlag()/PopItemFlag() - inherited by Begin() ImVector<ImGuiItemFlags> ItemFlagsStack; // Stack for PushItemFlag()/PopItemFlag() - inherited by Begin()
ImVector<ImGuiGroupData> GroupStack; // Stack for BeginGroup()/EndGroup() - not inherited by Begin() ImVector<ImGuiGroupData> GroupStack; // Stack for BeginGroup()/EndGroup() - not inherited by Begin()
ImVector<ImGuiPopupData> OpenPopupStack; // Which popups are open (persistent) ImVector<ImGuiPopupData> OpenPopupStack; // Which popups are open (persistent)