ソースを参照

Nav: Made hovering non-MenuItem Selectable not re-assign the source item for keyboard navigation.

omar 6 年 前
コミット
27079e68c2
3 ファイル変更15 行追加5 行削除
  1. 5 1
      docs/CHANGELOG.txt
  2. 2 1
      imgui_internal.h
  3. 8 3
      imgui_widgets.cpp

+ 5 - 1
docs/CHANGELOG.txt

@@ -35,9 +35,13 @@ HOW TO UPDATE?
 
 
 Other Changes:
 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
   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.
   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)
 
 
 
 
 -----------------------------------------------------------------------
 -----------------------------------------------------------------------

+ 2 - 1
imgui_internal.h

@@ -362,7 +362,8 @@ enum ImGuiSelectableFlagsPrivate_
     ImGuiSelectableFlags_PressedOnRelease   = 1 << 22,
     ImGuiSelectableFlags_PressedOnRelease   = 1 << 22,
     ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23,  // FIXME: We may be able to remove this (added in 6251d379 for menus)
     ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23,  // FIXME: We may be able to remove this (added in 6251d379 for menus)
     ImGuiSelectableFlags_AllowItemOverlap   = 1 << 24,
     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_
 // Extend ImGuiTreeNodeFlags_

+ 8 - 3
imgui_widgets.cpp

@@ -5472,13 +5472,16 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
     const bool was_selected = selected;
     const bool was_selected = selected;
     bool hovered, held;
     bool hovered, held;
     bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags);
     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)
         if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent)
         {
         {
             g.NavDisableHighlight = true;
             g.NavDisableHighlight = true;
             SetNavID(id, window->DC.NavLayerCurrent);
             SetNavID(id, window->DC.NavLayerCurrent);
         }
         }
+    }
     if (pressed)
     if (pressed)
         MarkItemEdited(id);
         MarkItemEdited(id);
 
 
@@ -6178,7 +6181,9 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo
     ImVec2 pos = window->DC.CursorPos;
     ImVec2 pos = window->DC.CursorPos;
     ImVec2 label_size = CalcTextSize(label, NULL, true);
     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;
     bool pressed;
     if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
     if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
     {
     {