From 27079e68c2c045a53991c6546b4693f275229d17 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 31 Jul 2019 10:36:40 -0700 Subject: [PATCH] Nav: Made hovering non-MenuItem Selectable not re-assign the source item for keyboard navigation. --- docs/CHANGELOG.txt | 6 +++++- imgui_internal.h | 3 ++- imgui_widgets.cpp | 11 ++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 78d67db35..3c5904b56 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -35,9 +35,13 @@ HOW TO UPDATE? Other Changes: -- Scrolling, Nav: Fixed programmatic scroll leading to a slightly incorrect scroll offset when +- Nav, Scrolling: Fixed programmatic scroll leading to a slightly incorrect scroll offset when the window has decorations or a menu-bar (broken in 1.71). This was mostly noticeable when a keyboard/gamepad movement led to scrolling the view, or using e.g. SetScrollHereY() function. +- Nav: Made hovering non-MenuItem Selectable not re-assign the source item for keyboard navigation. +- Nav: Fixed an issue with NavFlattened window flag (beta) where widgets not entirely fitting + in child window (often selectables because of their protruding sides) would be not considered + as entry points to to navigate toward the child window. (#787) ----------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index 6a672edca..23bf45f35 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -362,7 +362,8 @@ enum ImGuiSelectableFlagsPrivate_ ImGuiSelectableFlags_PressedOnRelease = 1 << 22, ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23, // FIXME: We may be able to remove this (added in 6251d379 for menus) ImGuiSelectableFlags_AllowItemOverlap = 1 << 24, - ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 25 // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. + ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 25, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. + ImGuiSelectableFlags_SetNavIdOnHover = 1 << 26 }; // Extend ImGuiTreeNodeFlags_ diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 07e8d2e34..84f2ea475 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5472,13 +5472,16 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl const bool was_selected = selected; bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags); - // Hovering selectable with mouse updates NavId accordingly so navigation can be resumed with gamepad/keyboard (this doesn't happen on most widgets) - if (pressed || hovered) + + // Update NavId when clicking or when Hovering (this doesn't happen on most widgets), so navigation can be resumed with gamepad/keyboard + if (pressed || (hovered && (flags & ImGuiSelectableFlags_SetNavIdOnHover))) + { if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent) { g.NavDisableHighlight = true; SetNavID(id, window->DC.NavLayerCurrent); } + } if (pressed) MarkItemEdited(id); @@ -6178,7 +6181,9 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo ImVec2 pos = window->DC.CursorPos; ImVec2 label_size = CalcTextSize(label, NULL, true); - ImGuiSelectableFlags flags = ImGuiSelectableFlags_PressedOnRelease | (enabled ? 0 : ImGuiSelectableFlags_Disabled); + // We've been using the equivalent of ImGuiSelectableFlags_SetNavIdOnHover on all Selectable() since early Nav system days (commit 43ee5d73), + // but I am unsure whether this should be kept at all. For now moved it to be an opt-in feature used by menus only. + ImGuiSelectableFlags flags = ImGuiSelectableFlags_PressedOnRelease | ImGuiSelectableFlags_SetNavIdOnHover | (enabled ? 0 : ImGuiSelectableFlags_Disabled); bool pressed; if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) {