From 344140004bbc3546443a546913688e810f84a1db Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 5 Mar 2019 22:09:25 +0100 Subject: [PATCH] Fixed IsItemDeactivated()/IsItemDeactivatedAfterEdit() from not correctly returning true when tabbing out of a focusable widget (Input/Slider/Drag) in most situations. (#2215, #1875) + Minor renaming of a local variable in widget code. --- docs/CHANGELOG.txt | 6 ++++-- imgui.cpp | 5 +++++ imgui_widgets.cpp | 12 ++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4f1faee6d..7f002f30b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -44,10 +44,12 @@ Other Changes: - Added GetBackgroundDrawList() helper to quickly get access to a ImDrawList that will be rendered behind every other windows. (#2391) -- Nav: Fixed a tap on AltGR (e.g. German keyboard) from navigating to the menu layer. -- Nav: Fixed Ctrl+Tab keeping active InputText() of a previous window active after the switch. (#2380) - DragScalar, InputScalar, SliderScalar: Added support for u8/s8/u16/s16 data types. We are reusing function instances for larger types to reduce code size. (#643, #320, #708, #1011) +- Nav: Fixed a tap on AltGR (e.g. German keyboard) from navigating to the menu layer. +- Nav: Fixed Ctrl+Tab keeping active InputText() of a previous window active after the switch. (#2380) +- Fixed IsItemDeactivated()/IsItemDeactivatedAfterEdit() from not correctly returning true + when tabbing out of a focusable widget (Input/Slider/Drag) in most situations. (#2215, #1875) - InputInt, InputFloat, InputScalar: Fix to keep the label of the +/- buttons centered when style.FramePadding.x is abnormally larger than style.FramePadding.y. Since the buttons are meant to be square (to align with e.g. color button) we always use FramePadding.y. (#2367) diff --git a/imgui.cpp b/imgui.cpp index 6d47dc8c9..4805c6731 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2891,6 +2891,7 @@ bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged return false; } +// Process TAB/Shift+TAB. Be mindful that this function may _clear_ the ActiveID when tabbing out. bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id) { ImGuiContext& g = *GImGui; @@ -2919,6 +2920,10 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id) g.NavJustTabbedId = id; return true; } + + // If another item is about to be focused, we clear our own active id + if (g.ActiveId == id) + ClearActiveID(); } return false; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 63583c34f..a36836131 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1950,14 +1950,14 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa // Tabbing or CTRL-clicking on Drag turns it into an input box bool start_text_input = false; - const bool tab_focus_requested = FocusableItemRegister(window, id); - if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0])) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id)) + const bool focus_requested = FocusableItemRegister(window, id); + if (focus_requested || (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0])) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id)) { SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); - if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0] || g.NavInputId == id) + if (focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0] || g.NavInputId == id) { start_text_input = true; g.ScalarAsInputTextId = 0; @@ -2385,15 +2385,15 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co // Tabbing or CTRL-clicking on Slider turns it into an input box bool start_text_input = false; - const bool tab_focus_requested = FocusableItemRegister(window, id); + const bool focus_requested = FocusableItemRegister(window, id); const bool hovered = ItemHoverable(frame_bb, id); - if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id)) + if (focus_requested || (hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id)) { SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); - if (tab_focus_requested || g.IO.KeyCtrl || g.NavInputId == id) + if (focus_requested || g.IO.KeyCtrl || g.NavInputId == id) { start_text_input = true; g.ScalarAsInputTextId = 0;