Skip to content

Commit 99913b5

Browse files
committed
Internals: added IsKeyChordPressed() for consistency.
1 parent a8bdbfd commit 99913b5

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

imgui.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -9141,16 +9141,10 @@ void ImGui::SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags)
91419141
}
91429142
}
91439143

9144-
bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
9144+
// This is equivalent to comparing KeyMods + doing a IsKeyPressed()
9145+
bool ImGui::IsKeyChordPressed(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
91459146
{
91469147
ImGuiContext& g = *GImGui;
9147-
9148-
// When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any.
9149-
if ((flags & ImGuiInputFlags_RouteMask_) == 0)
9150-
flags |= ImGuiInputFlags_RouteFocused;
9151-
if (!SetShortcutRouting(key_chord, owner_id, flags))
9152-
return false;
9153-
91549148
if (key_chord & ImGuiMod_Shortcut)
91559149
key_chord = ConvertShortcutMod(key_chord);
91569150
ImGuiKey mods = (ImGuiKey)(key_chord & ImGuiMod_Mask_);
@@ -9161,11 +9155,22 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags
91619155
ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_);
91629156
if (key == ImGuiKey_None)
91639157
key = ConvertSingleModFlagToKey(&g, mods);
9164-
91659158
if (!IsKeyPressed(key, owner_id, (flags & (ImGuiInputFlags_Repeat | (ImGuiInputFlags)ImGuiInputFlags_RepeatRateMask_))))
91669159
return false;
9167-
IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByShortcut) == 0); // Passing flags not supported by this function!
9160+
return true;
9161+
}
91689162

9163+
bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
9164+
{
9165+
// When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any.
9166+
if ((flags & ImGuiInputFlags_RouteMask_) == 0)
9167+
flags |= ImGuiInputFlags_RouteFocused;
9168+
if (!SetShortcutRouting(key_chord, owner_id, flags))
9169+
return false;
9170+
9171+
if (!IsKeyChordPressed(key_chord, owner_id, flags))
9172+
return false;
9173+
IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByShortcut) == 0); // Passing flags not supported by this function!
91699174
return true;
91709175
}
91719176

imgui_internal.h

+4
Original file line numberDiff line numberDiff line change
@@ -3131,6 +3131,10 @@ namespace ImGui
31313131
// - Route is granted to a single owner. When multiple requests are made we have policies to select the winning route.
31323132
// - Multiple read sites may use the same owner id and will all get the granted route.
31333133
// - For routing: when owner_id is 0 we use the current Focus Scope ID as a default owner in order to identify our location.
3134+
// - TL;DR;
3135+
// - IsKeyChordPressed() compares mods + call IsKeyPressed() -> function has no side-effect.
3136+
// - Shortcut() submits a route then if currently can be routed calls IsKeyChordPressed() -> function has (desirable) side-effects.
3137+
IMGUI_API bool IsKeyChordPressed(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags = 0);
31343138
IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
31353139
IMGUI_API bool SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
31363140
IMGUI_API bool TestShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id);

0 commit comments

Comments
 (0)