From 9ba202821f6d5dddf6caf3ea412c97c9e50271d0 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 4 Jan 2019 19:03:56 +0100 Subject: [PATCH] Nav: Fixed an keyboard issue where holding Activate/Space for longer than two frames on a button would unnecessary keep the focus on the parent window, which could steal it from newly appearing windows. (#787) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 1 + imgui.h | 2 +- imgui_widgets.cpp | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5af45c635..bfbd0ca74 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -63,6 +63,8 @@ Other Changes: - Window: Fixed using SetNextWindowPos() on a child window (which wasn't really documented) position the cursor as expected in the parent window, so there is no mismatch between the layout in parent and the position of the child window. - InputFloat: When using ImGuiInputTextFlags_ReadOnly the step buttons are disabled. (#2257) +- Nav: Fixed an keyboard issue where holding Activate/Space for longer than two frames on a button would unnecessary + keep the focus on the parent window, which could steal it from newly appearing windows. (#787) - Error recovery: Extraneous/undesired calls to End() are now being caught by an assert in the End() function itself at the call site (instead of being reported in EndFrame). Past the assert, they don't lead to crashes any more. (#1651) - Error recovery: Missing calls to End(), pass the assert, should not lead to crashes or to the fallback Debug window diff --git a/imgui.cpp b/imgui.cpp index d206a8e42..07e26e0c9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2533,6 +2533,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) } } +// FIXME-NAV: The existence of SetNavID/SetNavIDWithRectRel/SetFocusID is incredibly messy and confusing and needs some explanation or refactoring. void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) { ImGuiContext& g = *GImGui; diff --git a/imgui.h b/imgui.h index bd4b72035..8c0a95ac1 100644 --- a/imgui.h +++ b/imgui.h @@ -1282,7 +1282,7 @@ struct ImGuiIO bool KeySuper; // Keyboard modifier pressed: Cmd/Super/Windows bool KeysDown[512]; // Keyboard keys that are pressed (ideally left in the "native" order your engine has access to keyboard keys, so you can use your own defines/enums for keys). ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. - float NavInputs[ImGuiNavInput_COUNT]; // Gamepad inputs (keyboard keys will be auto-mapped and be written here by ImGui::NewFrame, all values will be cleared back to zero in ImGui::EndFrame) + float NavInputs[ImGuiNavInput_COUNT]; // Gamepad inputs. Cleared back to zero by EndFrame(). Keyboard keys will be auto-mapped and be written here by NewFrame(). // Functions IMGUI_API void AddInputCharacter(ImWchar c); // Add new character into InputCharacters[] diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 32d52da51..7f6b86e87 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -488,7 +488,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool // Set active id so it can be queried by user via IsItemActive(), equivalent of holding the mouse button. g.NavActivateId = id; // This is so SetActiveId assign a Nav source SetActiveID(id, window); - if (!(flags & ImGuiButtonFlags_NoNavFocus)) + if ((nav_activated_by_code || nav_activated_by_inputs) && !(flags & ImGuiButtonFlags_NoNavFocus)) SetFocusID(id, window); g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right) | (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); }