Inputs: added basic Shortcut() function - no routing yet. (#456)

This commit is contained in:
ocornut
2022-07-05 14:48:55 +02:00
parent 8c95c084cb
commit c59ebb2d71
2 changed files with 29 additions and 2 deletions

View File

@ -8420,6 +8420,26 @@ void ImGui::SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags)
SetKeyOwner(key, id, flags);
}
// - Need to decide how to handle shortcut translations for Non-Mac <> Mac
// - Ideas: https://github.com/ocornut/imgui/issues/456#issuecomment-264390864
bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
{
ImGuiContext& g = *GImGui;
ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_);
ImGuiKey mods = (ImGuiKey)(key_chord & ImGuiMod_Mask_);
if (g.IO.KeyMods != mods)
return false;
// Special storage location for mods
if (key == ImGuiKey_None)
key = ConvertSingleModFlagToKey(mods);
if (!IsKeyPressed(key, owner_id, (flags & (ImGuiInputFlags_Repeat | ImGuiInputFlags_RepeatRateMask_))))
return false;
return true;
}
//-----------------------------------------------------------------------------
// [SECTION] ERROR CHECKING
//-----------------------------------------------------------------------------