mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-25 13:07:01 +00:00
Internals: added IsKeyChordPressed() for consistency.
This commit is contained in:
parent
a8bdbfddf9
commit
99913b5051
25
imgui.cpp
25
imgui.cpp
@ -9141,16 +9141,10 @@ void ImGui::SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
|
// This is equivalent to comparing KeyMods + doing a IsKeyPressed()
|
||||||
|
bool ImGui::IsKeyChordPressed(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
|
||||||
// When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any.
|
|
||||||
if ((flags & ImGuiInputFlags_RouteMask_) == 0)
|
|
||||||
flags |= ImGuiInputFlags_RouteFocused;
|
|
||||||
if (!SetShortcutRouting(key_chord, owner_id, flags))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (key_chord & ImGuiMod_Shortcut)
|
if (key_chord & ImGuiMod_Shortcut)
|
||||||
key_chord = ConvertShortcutMod(key_chord);
|
key_chord = ConvertShortcutMod(key_chord);
|
||||||
ImGuiKey mods = (ImGuiKey)(key_chord & ImGuiMod_Mask_);
|
ImGuiKey mods = (ImGuiKey)(key_chord & ImGuiMod_Mask_);
|
||||||
@ -9161,11 +9155,22 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags
|
|||||||
ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_);
|
ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_);
|
||||||
if (key == ImGuiKey_None)
|
if (key == ImGuiKey_None)
|
||||||
key = ConvertSingleModFlagToKey(&g, mods);
|
key = ConvertSingleModFlagToKey(&g, mods);
|
||||||
|
|
||||||
if (!IsKeyPressed(key, owner_id, (flags & (ImGuiInputFlags_Repeat | (ImGuiInputFlags)ImGuiInputFlags_RepeatRateMask_))))
|
if (!IsKeyPressed(key, owner_id, (flags & (ImGuiInputFlags_Repeat | (ImGuiInputFlags)ImGuiInputFlags_RepeatRateMask_))))
|
||||||
return false;
|
return false;
|
||||||
IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByShortcut) == 0); // Passing flags not supported by this function!
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
|
||||||
|
{
|
||||||
|
// When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any.
|
||||||
|
if ((flags & ImGuiInputFlags_RouteMask_) == 0)
|
||||||
|
flags |= ImGuiInputFlags_RouteFocused;
|
||||||
|
if (!SetShortcutRouting(key_chord, owner_id, flags))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!IsKeyChordPressed(key_chord, owner_id, flags))
|
||||||
|
return false;
|
||||||
|
IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByShortcut) == 0); // Passing flags not supported by this function!
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3131,6 +3131,10 @@ namespace ImGui
|
|||||||
// - Route is granted to a single owner. When multiple requests are made we have policies to select the winning route.
|
// - Route is granted to a single owner. When multiple requests are made we have policies to select the winning route.
|
||||||
// - Multiple read sites may use the same owner id and will all get the granted route.
|
// - Multiple read sites may use the same owner id and will all get the granted route.
|
||||||
// - For routing: when owner_id is 0 we use the current Focus Scope ID as a default owner in order to identify our location.
|
// - For routing: when owner_id is 0 we use the current Focus Scope ID as a default owner in order to identify our location.
|
||||||
|
// - TL;DR;
|
||||||
|
// - IsKeyChordPressed() compares mods + call IsKeyPressed() -> function has no side-effect.
|
||||||
|
// - Shortcut() submits a route then if currently can be routed calls IsKeyChordPressed() -> function has (desirable) side-effects.
|
||||||
|
IMGUI_API bool IsKeyChordPressed(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags = 0);
|
||||||
IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
|
IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
|
||||||
IMGUI_API bool SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
|
IMGUI_API bool SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
|
||||||
IMGUI_API bool TestShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id);
|
IMGUI_API bool TestShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user