mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Inputs: added wip/experiment routing system: Shortcut(), RoutingFocused policy, SetShortcutRouting(). (#456, #2637, #3724)
- InputText() uses Shortcut().
This commit is contained in:
		@@ -1277,6 +1277,32 @@ struct ImGuiInputEvent
 | 
			
		||||
#define ImGuiKeyOwner_Any           ((ImGuiID)0)    // Accept key that have an owner, UNLESS a call to SetKeyOwner() explicitely used ImGuiInputFlags_LockThisFrame or ImGuiInputFlags_LockUntilRelease.
 | 
			
		||||
#define ImGuiKeyOwner_None          ((ImGuiID)-1)   // Require key to have no owner.
 | 
			
		||||
 | 
			
		||||
typedef ImS16 ImGuiKeyRoutingIndex;
 | 
			
		||||
 | 
			
		||||
// Routing table entry (sizeof() == 16 bytes)
 | 
			
		||||
struct ImGuiKeyRoutingData
 | 
			
		||||
{
 | 
			
		||||
    ImGuiKeyRoutingIndex            NextEntryIndex;
 | 
			
		||||
    ImU16                           Mods;
 | 
			
		||||
    ImU8                            RoutingNextScore;               // Lower is better (0: perfect score)
 | 
			
		||||
    ImGuiID                         RoutingCurr;
 | 
			
		||||
    ImGuiID                         RoutingNext;
 | 
			
		||||
 | 
			
		||||
    ImGuiKeyRoutingData()           { NextEntryIndex = -1; Mods = 0; RoutingNextScore = 255; RoutingCurr = RoutingNext = ImGuiKeyOwner_None; }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Routing table maintain a desired owner for each possible key-chord (key + mods), and setup owner in NewFrame() when mods are matching.
 | 
			
		||||
// Stored in main context (1 instance)
 | 
			
		||||
struct ImGuiKeyRoutingTable
 | 
			
		||||
{
 | 
			
		||||
    ImGuiKeyRoutingIndex            Index[ImGuiKey_NamedKey_COUNT]; // Index of first entry in Entries[]
 | 
			
		||||
    ImVector<ImGuiKeyRoutingData>   Entries;
 | 
			
		||||
    ImVector<ImGuiKeyRoutingData>   EntriesNext;                    // Double-buffer to avoid reallocation (could use a shared buffer)
 | 
			
		||||
 | 
			
		||||
    ImGuiKeyRoutingTable()          { Clear(); }
 | 
			
		||||
    void Clear()                    { for (int n = 0; n < IM_ARRAYSIZE(Index); n++) Index[n] = -1; Entries.clear(); EntriesNext.clear(); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// This extend ImGuiKeyData but only for named keys (legacy keys don't support the new features)
 | 
			
		||||
// Stored in main context (1 per named key). In the future might be merged into ImGuiKeyData.
 | 
			
		||||
struct ImGuiKeyOwnerData
 | 
			
		||||
@@ -1310,6 +1336,16 @@ enum ImGuiInputFlags_
 | 
			
		||||
    // Flags for SetKeyOwner(), SetItemKeyOwner()
 | 
			
		||||
    ImGuiInputFlags_LockThisFrame       = 1 << 6,   // Access to key data will requires EXPLICIT owner ID (ImGuiKeyOwner_Any/0 will NOT accepted for polling). Cleared at end of frame. This is useful to make input-owner-aware code steal keys from non-input-owner-aware code.
 | 
			
		||||
    ImGuiInputFlags_LockUntilRelease    = 1 << 7,   // Access to key data will requires EXPLICIT owner ID (ImGuiKeyOwner_Any/0 will NOT accepted for polling). Cleared when key is released or at end of frame is not down. This is useful to make input-owner-aware code steal keys from non-input-owner-aware code.
 | 
			
		||||
 | 
			
		||||
    // Flags for Shortcut(), SetShortcutRouting()
 | 
			
		||||
    // When Focus Routing is enabled, function will call SetShortcutRouting(): Accept inputs if currently in focus stack. Deep-most focused window takes inputs. ActiveId takes inputs over deep-most focused window.
 | 
			
		||||
    ImGuiInputFlags_RouteFocused        = 1 << 8,   // Enable focus routing
 | 
			
		||||
 | 
			
		||||
    // [Internal] Mask of which function support which flags
 | 
			
		||||
    ImGuiInputFlags_SupportedByIsKeyPressed     = ImGuiInputFlags_Repeat | ImGuiInputFlags_RepeatRateMask_,
 | 
			
		||||
    ImGuiInputFlags_SupportedByShortcut         = ImGuiInputFlags_Repeat | ImGuiInputFlags_RepeatRateMask_ | ImGuiInputFlags_RouteFocused,
 | 
			
		||||
    ImGuiInputFlags_SupportedBySetKeyOwner      = ImGuiInputFlags_LockThisFrame | ImGuiInputFlags_LockUntilRelease,
 | 
			
		||||
    ImGuiInputFlags_SupportedBySetItemKeyOwner  = ImGuiInputFlags_SupportedBySetKeyOwner | ImGuiInputFlags_CondMask_,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
@@ -1707,10 +1743,12 @@ struct ImGuiContext
 | 
			
		||||
    ImGuiID                 LastActiveId;                       // Store the last non-zero ActiveId, useful for animation.
 | 
			
		||||
    float                   LastActiveIdTimer;                  // Store the last non-zero ActiveId timer since the beginning of activation, useful for animation.
 | 
			
		||||
 | 
			
		||||
    // [EXPERIMENTAL] Key/Input Ownership
 | 
			
		||||
    // [EXPERIMENTAL] Key/Input Ownership + Shortcut Routing system
 | 
			
		||||
    // - The idea is that instead of "eating" a given key, we can link to an owner.
 | 
			
		||||
    // - Input query can then read input by specifying ImGuiKeyOwner_Any (== 0), ImGuiKeyOwner_None (== -1) or a custom ID.
 | 
			
		||||
    // - Routing is requested ahead of time for a given chord (Key + Mods) and granted in NewFrame().
 | 
			
		||||
    ImGuiKeyOwnerData       KeysOwnerData[ImGuiKey_NamedKey_COUNT];
 | 
			
		||||
    ImGuiKeyRoutingTable    KeysRoutingTable;
 | 
			
		||||
    ImU32                   ActiveIdUsingNavDirMask;            // Active widget will want to read those nav move requests (e.g. can activate a button and move away from it)
 | 
			
		||||
    bool                    ActiveIdUsingAllKeyboardKeys;       // Active widget will want to read all keyboard keys inputs. (FIXME: This is a shortcut for not taking ownership of 100+ keys but perhaps best to not have the inconsistency)
 | 
			
		||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
 | 
			
		||||
@@ -2817,12 +2855,19 @@ 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.
 | 
			
		||||
    // [EXPERIMENTAL] Shortcut Routing
 | 
			
		||||
    // - ImGuiKeyChord = a ImGuiKey optionally OR-red with ImGuiMod_Alt/ImGuiMod_Ctrl/ImGuiMod_Shift/ImGuiMod_Super.
 | 
			
		||||
    //     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.
 | 
			
		||||
    //   ONLY ImGuiMod_XXX values are legal to 'OR' with an ImGuiKey. You CANNOT 'OR' two ImGuiKey values.
 | 
			
		||||
    // - When using one of the routing flags (e.g. ImGuiInputFlags_RouteFocused): routes requested ahead of time given a chord (key + modifiers) and a routing policy.
 | 
			
		||||
    // - Routes are resolved during NewFrame(): if keyboard modifiers are matching current ones: SetKeyOwner() is called + route is granted for the frame.
 | 
			
		||||
    // - 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 a same owner and will all get the granted route.
 | 
			
		||||
    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, ImGuiWindow* location = NULL);
 | 
			
		||||
    IMGUI_API bool              TestShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id);
 | 
			
		||||
    IMGUI_API ImGuiKeyRoutingData* GetShortcutRoutingData(ImGuiKeyChord key_chord);
 | 
			
		||||
 | 
			
		||||
    // [EXPERIMENTAL] Focus Scope
 | 
			
		||||
    // This is generally used to identify a unique input location (for e.g. a selection set)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user