From f6d6880a61c3a3139fabcb63541b0339f8fa432b Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 14 Jan 2020 20:34:26 +0100 Subject: [PATCH] Internals: Nav: PushFocusScope, PopFocusScope, GetFocusScopeID() helpers --- imgui.cpp | 16 ++++++++++++++++ imgui_internal.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index c7e7a3c60..50cdf4ee8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6909,6 +6909,22 @@ void ImGui::ActivateItem(ImGuiID id) g.NavNextActivateId = id; } +void ImGui::PushFocusScope(ImGuiID id) +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + window->IDStack.push_back(window->DC.NavFocusScopeIdCurrent); + window->DC.NavFocusScopeIdCurrent = id; +} + +void ImGui::PopFocusScope() +{ + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + window->DC.NavFocusScopeIdCurrent = window->IDStack.back(); + window->IDStack.pop_back(); +} + void ImGui::SetKeyboardFocusHere(int offset) { IM_ASSERT(offset >= -1); // -1 is allowed but not below diff --git a/imgui_internal.h b/imgui_internal.h index 894519b28..a19c1811c 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1703,6 +1703,11 @@ namespace ImGui IMGUI_API void SetNavID(ImGuiID id, int nav_layer, int focus_scope_id); IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, int focus_scope_id, const ImRect& rect_rel); + // Focus scope (WIP) + IMGUI_API void PushFocusScope(ImGuiID id); // Note: this is storing in same stack as IDStack, so Push/Pop mismatch will be reported there. + IMGUI_API void PopFocusScope(); + inline ImGuiID GetFocusScopeID() { ImGuiContext& g = *GImGui; return g.NavFocusScopeId; } + // Inputs // FIXME: Eventually we should aim to move e.g. IsActiveIdUsingKey() into IsKeyXXX functions. inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; }