From fb4f1ff7f6dc55ea29b4cc7d391c1076f690165e Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 30 Jan 2019 15:16:09 +0100 Subject: [PATCH] InputText: Fixed a bug where ESCAPE would be first captured by the Keyboard Navigation code. (#2321, #787) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 4 +++- imgui_internal.h | 4 +++- imgui_widgets.cpp | 4 +++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7da1a5e7..1df96435 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -36,6 +36,7 @@ HOW TO UPDATE? Other Changes: - Added .editorconfig file for text editors to standardize using spaces. (#2038) [@kudaba] - InputText: Fixed a bug where ESCAPE would not restore the initial value in all situations. (#2321) [@relick] +- InputText: Fixed a bug where ESCAPE would be first captured by the Keyboard Navigation code. (#2321, #787) - Fixed range-version of PushID() and GetID() not honoring the ### operator to restart from the seed value. - Fixed CloseCurrentPopup() on a child-menu of a modal incorrectly closing the modal. (#2308) - Window: When resizing from an edge, the border is more visible and better follow the rounded corners. diff --git a/imgui.cpp b/imgui.cpp index 320b6644..2e26ddcb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2644,6 +2644,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) } g.ActiveId = id; g.ActiveIdAllowNavDirFlags = 0; + g.ActiveIdBlockNavInputFlags = 0; g.ActiveIdAllowOverlap = false; g.ActiveIdWindow = window; if (id) @@ -7630,7 +7631,8 @@ static void ImGui::NavUpdate() { if (g.ActiveId != 0) { - ClearActiveID(); + if (!(g.ActiveIdBlockNavInputFlags & (1 << ImGuiNavInput_Cancel))) + ClearActiveID(); } else if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow) && !(g.NavWindow->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->ParentWindow) { diff --git a/imgui_internal.h b/imgui_internal.h index 51953389..141c05ca 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -777,6 +777,7 @@ struct ImGuiContext bool ActiveIdPreviousFrameIsAlive; bool ActiveIdPreviousFrameHasBeenEdited; int ActiveIdAllowNavDirFlags; // Active widget allows using directional navigation (e.g. can activate a button and move away from it) + int ActiveIdBlockNavInputFlags; ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) ImGuiWindow* ActiveIdWindow; ImGuiWindow* ActiveIdPreviousFrameWindow; @@ -931,7 +932,8 @@ struct ImGuiContext ActiveIdHasBeenEdited = false; ActiveIdPreviousFrameIsAlive = false; ActiveIdPreviousFrameHasBeenEdited = false; - ActiveIdAllowNavDirFlags = 0; + ActiveIdAllowNavDirFlags = 0x00; + ActiveIdBlockNavInputFlags = 0x00; ActiveIdClickOffset = ImVec2(-1,-1); ActiveIdWindow = ActiveIdPreviousFrameWindow = NULL; ActiveIdSource = ImGuiInputSource_None; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 2d6a1465..496b9cb0 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2628,6 +2628,7 @@ bool ImGui::InputScalarAsWidgetReplacement(const ImRect& bb, ImGuiID id, const c SetActiveID(g.ScalarAsInputTextId, window); SetHoveredID(0); g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); + g.ActiveIdBlockNavInputFlags = (1 << ImGuiNavInput_Cancel); char fmt_buf[32]; char data_buf[32]; @@ -3257,8 +3258,9 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); + g.ActiveIdBlockNavInputFlags = (1 << ImGuiNavInput_Cancel); if (!is_multiline && !(flags & ImGuiInputTextFlags_CallbackHistory)) - g.ActiveIdAllowNavDirFlags |= ((1 << ImGuiDir_Up) | (1 << ImGuiDir_Down)); + g.ActiveIdAllowNavDirFlags = ((1 << ImGuiDir_Up) | (1 << ImGuiDir_Down)); } else if (io.MouseClicked[0]) {