mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-14 17:07:01 +00:00
Inputs: added basic Shortcut() function - no routing yet. (#456)
This commit is contained in:
parent
8c95c084cb
commit
c59ebb2d71
20
imgui.cpp
20
imgui.cpp
@ -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
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -1289,11 +1289,11 @@ struct ImGuiKeyOwnerData
|
||||
ImGuiKeyOwnerData() { OwnerCurr = OwnerNext = ImGuiKeyOwner_None; LockThisFrame = LockUntilRelease = false; }
|
||||
};
|
||||
|
||||
// Flags for extended versions of IsKeyPressed(), IsMouseClicked(), SetKeyOwner(), SetItemKeyOwner()
|
||||
// Flags for extended versions of IsKeyPressed(), IsMouseClicked(), Shortcut(), SetKeyOwner(), SetItemKeyOwner()
|
||||
// Don't mistake with ImGuiInputTextFlags! (for ImGui::InputText() function)
|
||||
enum ImGuiInputFlags_
|
||||
{
|
||||
// Flags for IsKeyPressed(), IsMouseClicked()
|
||||
// Flags for IsKeyPressed(), IsMouseClicked(), Shortcut()
|
||||
ImGuiInputFlags_None = 0,
|
||||
ImGuiInputFlags_Repeat = 1 << 0, // Return true on successive repeats. Default for legacy IsKeyPressed(). NOT Default for legacy IsMouseClicked(). MUST BE == 1.
|
||||
ImGuiInputFlags_RepeatRateDefault = 1 << 1, // Repeat rate: Regular (default)
|
||||
@ -2817,6 +2817,13 @@ namespace ImGui
|
||||
IMGUI_API bool IsMouseClicked(ImGuiMouseButton button, ImGuiID owner_id, ImGuiInputFlags flags = 0);
|
||||
IMGUI_API bool IsMouseReleased(ImGuiMouseButton button, ImGuiID owner_id);
|
||||
|
||||
// [EXPERIMENTAL] Shortcuts
|
||||
// - ImGuiKeyChord = any ImGuiKey optionally ORed with ImGuiMod_XXX values.
|
||||
// ImGuiKey_C (accepted by functions taking ImGuiKey or ImGuiKeyChord)
|
||||
// ImGuiKey_C | ImGuiMod_Ctrl (accepted by functions taking ImGuiKeyChord)
|
||||
// - ONLY ImGuiMod_XXX values are legal to 'OR' with an ImGuiKey. You CANNOT 'OR' two ImGuiKey values.
|
||||
IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
|
||||
|
||||
// [EXPERIMENTAL] Focus Scope
|
||||
// This is generally used to identify a unique input location (for e.g. a selection set)
|
||||
// There is one per window (automatically set in Begin), but:
|
||||
|
Loading…
Reference in New Issue
Block a user