Browse Source

Shortcuts: added flags to SetNextItemShortcut(). (#456)

ocornut 1 year ago
parent
commit
77e4171894
3 changed files with 18 additions and 12 deletions
  1. 16 11
      imgui.cpp
  2. 1 1
      imgui.h
  3. 1 0
      imgui_internal.h

+ 16 - 11
imgui.cpp

@@ -1112,6 +1112,9 @@ static void             SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport
 
 namespace ImGui
 {
+// Item
+static void             ItemHandleShortcut(ImGuiID id);
+
 // Navigation
 static void             NavUpdate();
 static void             NavUpdateWindowing();
@@ -9674,11 +9677,12 @@ bool ImGui::IsKeyChordPressed(ImGuiKeyChord key_chord, ImGuiInputFlags flags, Im
     return true;
 }
 
-void ImGui::SetNextItemShortcut(ImGuiKeyChord key_chord)
+void ImGui::SetNextItemShortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags)
 {
     ImGuiContext& g = *GImGui;
     g.NextItemData.Flags |= ImGuiNextItemDataFlags_HasShortcut;
     g.NextItemData.Shortcut = key_chord;
+    g.NextItemData.ShortcutFlags = flags;
 }
 
 bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags)
@@ -10012,18 +10016,19 @@ void ImGui::KeepAliveID(ImGuiID id)
         g.ActiveIdPreviousFrameIsAlive = true;
 }
 
-static void ItemHandleShortcut(ImGuiID id)
+void ImGui::ItemHandleShortcut(ImGuiID id)
 {
-    // FIXME: Generalize Activation queue?
     ImGuiContext& g = *GImGui;
-    if (ImGui::Shortcut(g.NextItemData.Shortcut, ImGuiInputFlags_None, id) && g.NavActivateId == 0)
-    {
-        g.NavActivateId = id; // Will effectively disable clipping.
-        g.NavActivateFlags = ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_FromShortcut;
-        //if (g.ActiveId == 0 || g.ActiveId == id)
-        g.NavActivateDownId = g.NavActivatePressedId = id;
-        ImGui::NavHighlightActivated(id);
-    }
+    ImGuiInputFlags flags = g.NextItemData.ShortcutFlags;
+    if (!Shortcut(g.NextItemData.Shortcut, flags, id) || g.NavActivateId != 0)
+        return;
+
+    // FIXME: Generalize Activation queue?
+    g.NavActivateId = id; // Will effectively disable clipping.
+    g.NavActivateFlags = ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_FromShortcut;
+    //if (g.ActiveId == 0 || g.ActiveId == id)
+    g.NavActivateDownId = g.NavActivatePressedId = id;
+    NavHighlightActivated(id);
 }
 
 // Declare item bounding box for clipping and interaction.

+ 1 - 1
imgui.h

@@ -955,7 +955,7 @@ namespace ImGui
     //   - Shortcut() submits a route, routes are resolved, if it currently can be routed it calls IsKeyChordPressed() -> function has (desirable) side-effects as it can prevents another call from getting the route.
     // - Visualize registered routes in 'Metrics/Debugger->Inputs'.
     IMGUI_API bool          Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0);
-    IMGUI_API void          SetNextItemShortcut(ImGuiKeyChord key_chord);
+    IMGUI_API void          SetNextItemShortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0);
 
     // Inputs Utilities: Mouse specific
     // - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right.

+ 1 - 0
imgui_internal.h

@@ -1186,6 +1186,7 @@ struct ImGuiNextItemData
     ImGuiSelectionUserData      SelectionUserData;  // Set by SetNextItemSelectionUserData() (note that NULL/0 is a valid value, we use -1 == ImGuiSelectionUserData_Invalid to mark invalid values)
     float                       Width;              // Set by SetNextItemWidth()
     ImGuiKeyChord               Shortcut;           // Set by SetNextItemShortcut()
+    ImGuiInputFlags             ShortcutFlags;      // Set by SetNextItemShortcut()
     bool                        OpenVal;            // Set by SetNextItemOpen()
     ImGuiCond                   OpenCond : 8;