From 0a154b30ad0f628256e3cd61b50ceb0840a1f335 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 3 Sep 2021 17:27:17 +0200 Subject: [PATCH] Nav, ButtonBehavior: reworked old code which ended up 1) calling SetActiveId repeately and 2) misleadingly set g.NavActivateId (amend af38749e) --- imgui_widgets.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index c9cdcff7..0ac0fb05 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -604,13 +604,12 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool bool nav_activated_by_code = (g.NavActivateId == id); bool nav_activated_by_inputs = IsNavInputTest(ImGuiNavInput_Activate, (flags & ImGuiButtonFlags_Repeat) ? ImGuiInputReadMode_Repeat : ImGuiInputReadMode_Pressed); if (nav_activated_by_code || nav_activated_by_inputs) - pressed = true; - if (nav_activated_by_code || nav_activated_by_inputs || g.ActiveId == id) { // 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 + pressed = true; SetActiveID(id, window); - if ((nav_activated_by_code || nav_activated_by_inputs) && !(flags & ImGuiButtonFlags_NoNavFocus)) + g.ActiveIdSource = ImGuiInputSource_Nav; + if (!(flags & ImGuiButtonFlags_NoNavFocus)) SetFocusID(id, window); } }