Browse Source

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

pull/7617/head
ocornut 6 months ago
parent
commit
77e4171894
  1. 27
      imgui.cpp
  2. 2
      imgui.h
  3. 1
      imgui_internal.h

27
imgui.cpp

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

2
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. // - 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'. // - Visualize registered routes in 'Metrics/Debugger->Inputs'.
IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0); 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 // Inputs Utilities: Mouse specific
// - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right. // - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right.

1
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) 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() float Width; // Set by SetNextItemWidth()
ImGuiKeyChord Shortcut; // Set by SetNextItemShortcut() ImGuiKeyChord Shortcut; // Set by SetNextItemShortcut()
ImGuiInputFlags ShortcutFlags; // Set by SetNextItemShortcut()
bool OpenVal; // Set by SetNextItemOpen() bool OpenVal; // Set by SetNextItemOpen()
ImGuiCond OpenCond : 8; ImGuiCond OpenCond : 8;

Loading…
Cancel
Save