From d6ce800a209152b00adfc0bfd15056a132095bf1 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 30 Jul 2016 14:31:34 +0200 Subject: [PATCH] Nav: ActiveIdAllowNavMove -> ActiveIdAllowNavDirFlags for more flexibility (nav up/down typically allowed on a single-line text input) (#323) --- imgui.cpp | 22 ++++++++++++---------- imgui_internal.h | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 08195ca08..bbf803525 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1824,7 +1824,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window = NULL) ImGuiContext& g = *GImGui; g.ActiveIdIsJustActivated = (g.ActiveId != id); g.ActiveId = id; - g.ActiveIdAllowNavMove = false; + g.ActiveIdAllowNavDirFlags = 0; g.ActiveIdAllowOverlap = false; g.ActiveIdWindow = window; if (id) @@ -1847,7 +1847,7 @@ void ImGui::SetActiveIDNoNav(ImGuiID id, ImGuiWindow* window) ImGuiContext& g = *GImGui; g.ActiveIdIsJustActivated = (g.ActiveId != id); g.ActiveId = id; - g.ActiveIdAllowNavMove = false; + g.ActiveIdAllowNavDirFlags = 0; g.ActiveIdAllowOverlap = false; g.ActiveIdWindow = window; g.ActiveIdSource = (g.NavActivateId == id || g.NavInputId == id) ? ImGuiInputSource_Nav : ImGuiInputSource_Mouse; @@ -2511,13 +2511,14 @@ static void NavUpdate() g.NavMoveRequest = false; // Initiate directional inputs request + const int allowed_dir_flags = (g.ActiveId == 0) ? ~0 : g.ActiveIdAllowNavDirFlags; g.NavMoveDir = ImGuiNavDir_None; - if (g.FocusedWindow && !g.NavWindowingTarget && (g.ActiveId == 0 || g.ActiveIdAllowNavMove) && !(g.FocusedWindow->Flags & ImGuiWindowFlags_NoNav)) + if (g.FocusedWindow && !g.NavWindowingTarget && allowed_dir_flags && !(g.FocusedWindow->Flags & ImGuiWindowFlags_NoNav)) { - if (IsKeyPressedMap(ImGuiKey_NavLeft, true)) g.NavMoveDir = ImGuiNavDir_Left; - if (IsKeyPressedMap(ImGuiKey_NavRight, true)) g.NavMoveDir = ImGuiNavDir_Right; - if (IsKeyPressedMap(ImGuiKey_NavUp, true)) g.NavMoveDir = ImGuiNavDir_Up; - if (IsKeyPressedMap(ImGuiKey_NavDown, true)) g.NavMoveDir = ImGuiNavDir_Down; + if ((allowed_dir_flags & (1<