mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-28 00:39:02 +08:00
Internals: tidying up and stripping more of focus scope code.
This commit is contained in:
parent
9f66a3a9ed
commit
7109f32f96
26
imgui.cpp
26
imgui.cpp
@ -6329,9 +6329,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
window->ParentWindowInBeginStack = parent_window_in_stack;
|
window->ParentWindowInBeginStack = parent_window_in_stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to focus scope stack - inherited by default by child windows from parent, reset by regular window
|
// Add to focus scope stack
|
||||||
//if (window == window->RootWindow && (window->Flags & ImGuiWindowFlags_ChildMenu) == 0)
|
PushFocusScope(window->ID);
|
||||||
PushFocusScope(window->ID);
|
|
||||||
window->NavRootFocusScopeId = g.CurrentFocusScopeId;
|
window->NavRootFocusScopeId = g.CurrentFocusScopeId;
|
||||||
g.CurrentWindow = NULL;
|
g.CurrentWindow = NULL;
|
||||||
|
|
||||||
@ -6942,8 +6941,7 @@ void ImGui::End()
|
|||||||
if (window->DC.CurrentColumns)
|
if (window->DC.CurrentColumns)
|
||||||
EndColumns();
|
EndColumns();
|
||||||
PopClipRect(); // Inner window clip rectangle
|
PopClipRect(); // Inner window clip rectangle
|
||||||
//if (window == window->RootWindow && (window->Flags & ImGuiWindowFlags_ChildMenu) == 0)
|
PopFocusScope();
|
||||||
PopFocusScope();
|
|
||||||
|
|
||||||
// Stop logging
|
// Stop logging
|
||||||
if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of 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)
|
void ImGui::PushFocusScope(ImGuiID id)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
if (g.FocusScopeStackLocked > 0)
|
g.FocusScopeStack.push_back(id);
|
||||||
return;
|
g.CurrentFocusScopeId = id;
|
||||||
ImGuiFocusScope scope;
|
|
||||||
scope.FocusScopeId = id;
|
|
||||||
scope.Window = g.CurrentWindow;
|
|
||||||
g.FocusScopeStack.push_back(scope);
|
|
||||||
g.CurrentFocusScopeId = scope.FocusScopeId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::PopFocusScope()
|
void ImGui::PopFocusScope()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
if (g.FocusScopeStackLocked > 0)
|
|
||||||
return;
|
|
||||||
IM_ASSERT(g.FocusScopeStack.Size > 0); // Too many PopFocusScope() ?
|
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.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!
|
// 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.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;
|
inner_rect_rel.Max.y = clamp_y ? (inner_rect_rel.Max.y - pad_y) : +FLT_MAX;
|
||||||
window->NavRectRel[g.NavLayer].ClipWithFull(inner_rect_rel);
|
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
|
// 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)))
|
if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow)))
|
||||||
g.NavWindow->NavLastIds[0] = 0;
|
g.NavWindow->NavLastIds[0] = 0;
|
||||||
g.NavId = /*g.NavFocusScopeId =*/ 0;
|
g.NavId = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1388,14 +1388,6 @@ struct ImGuiNavItemData
|
|||||||
void Clear() { Window = NULL; ID = FocusScopeId = 0; InFlags = 0; DistBox = DistCenter = DistAxial = FLT_MAX; }
|
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
|
// [SECTION] Columns support
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -1696,7 +1688,7 @@ struct ImGuiContext
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Next window/item data
|
// Next window/item data
|
||||||
ImGuiID CurrentFocusScopeId; // == g.FocusScopeStack.back().FocusScopeId
|
ImGuiID CurrentFocusScopeId; // == g.FocusScopeStack.back()
|
||||||
ImGuiItemFlags CurrentItemFlags; // == g.ItemFlagsStack.back()
|
ImGuiItemFlags CurrentItemFlags; // == g.ItemFlagsStack.back()
|
||||||
ImGuiNextItemData NextItemData; // Storage for SetNextItem** functions
|
ImGuiNextItemData NextItemData; // Storage for SetNextItem** functions
|
||||||
ImGuiLastItemData LastItemData; // Storage for last submitted item (setup by ItemAdd)
|
ImGuiLastItemData LastItemData; // Storage for last submitted item (setup by ItemAdd)
|
||||||
@ -1706,13 +1698,12 @@ 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<ImGuiFocusScope> FocusScopeStack; // Stack for PushFocusScope()/PopFocusScope() - inherited by BeginChild(), pushed into by Begin()
|
ImVector<ImGuiID> 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)
|
||||||
ImVector<ImGuiPopupData>BeginPopupStack; // Which level of BeginPopup() we are in (reset every frame)
|
ImVector<ImGuiPopupData>BeginPopupStack; // Which level of BeginPopup() we are in (reset every frame)
|
||||||
int BeginMenuCount;
|
int BeginMenuCount;
|
||||||
int FocusScopeStackLocked; // Prevent PushFocusScope()/PopFocusScope()
|
|
||||||
|
|
||||||
// Viewports
|
// Viewports
|
||||||
ImVector<ImGuiViewportP*> Viewports; // Active viewports (Size==1 in 'master' branch). Each viewports hold their copy of ImDrawData.
|
ImVector<ImGuiViewportP*> Viewports; // Active viewports (Size==1 in 'master' branch). Each viewports hold their copy of ImDrawData.
|
||||||
@ -1950,7 +1941,6 @@ struct ImGuiContext
|
|||||||
CurrentFocusScopeId = 0;
|
CurrentFocusScopeId = 0;
|
||||||
CurrentItemFlags = ImGuiItemFlags_None;
|
CurrentItemFlags = ImGuiItemFlags_None;
|
||||||
BeginMenuCount = 0;
|
BeginMenuCount = 0;
|
||||||
FocusScopeStackLocked = 0;
|
|
||||||
|
|
||||||
NavWindow = NULL;
|
NavWindow = NULL;
|
||||||
NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavActivateInputId = 0;
|
NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavActivateInputId = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user