|
TachyonUI 1.1.0
High-performance UI for building tools.
|
Registry of commands: named actions with an optional icon and an optional shortcut key, each firing one callback when invoked (clicked from a menu / toolbar, or via its key). More...
#include <gui_core/input/gui_command_manager.h>
Classes | |
| struct | Command |
| A registered command. More... | |
Public Member Functions | |
| UndoHistory & | History () |
| The app's undo history (text fields push their edits to it). | |
| const UndoHistory & | History () const |
| CommandManager () | |
| CommandMode | RegisterMode (std::string_view name) |
| Registers a named mode and returns the CommandMode to use when registering commands or calling SetMode. | |
| std::string_view | GetModeName (CommandMode mode) const |
| The name mode was registered with; empty for an unknown mode. | |
| uint32_t | GetModeCount () const |
| void | SetMode (CommandMode mode) |
| Makes mode the active mode, whose shortcuts are tried before Default. | |
| CommandMode | GetMode () const |
| CommandID | RegisterCommand (CommandMode mode, IconID icon, KeyCode key, KeyModifier modifiers, std::function< void()> callback, std::string_view description={}) |
| Registers callback in mode; description names it in menus and shortcut lists. | |
| CommandID | RegisterCommand (IconID icon, KeyCode key, KeyModifier modifiers, std::function< void()> callback, std::string_view description={}) |
| RegisterCommand in the Default mode. | |
| CommandID | RegisterCommand (CommandMode mode, KeyCode key, KeyModifier modifiers, std::function< void()> callback, std::string_view description={}) |
| RegisterCommand without an icon. | |
| CommandID | RegisterCommand (KeyCode key, KeyModifier modifiers, std::function< void()> callback, std::string_view description={}) |
| RegisterCommand in the Default mode, without an icon. | |
| CommandID | RegisterCommand (CommandMode mode, IconID icon, std::function< void()> callback, std::string_view description={}) |
| RegisterCommand without a shortcut key. | |
| CommandID | RegisterCommand (IconID icon, std::function< void()> callback, std::string_view description={}) |
| RegisterCommand in the Default mode, without a shortcut key. | |
| CommandID | RegisterHeldCommand (CommandMode mode, IconID icon, KeyCode key, KeyModifier modifiers, std::function< void()> onBegin, std::function< void()> onEnd, std::string_view description={}) |
| Registers a hold-to-act command (pan, orbit): onBegin on press, onEnd on release. | |
| CommandID | RegisterHeldCommand (KeyCode key, KeyModifier modifiers, std::function< void()> onBegin, std::function< void()> onEnd, std::string_view description={}) |
| RegisterHeldCommand in the Default mode, without an icon. | |
| CommandID | RegisterHeldCommand (CommandMode mode, KeyCode key, KeyModifier modifiers, std::function< void()> onBegin, std::function< void()> onEnd, std::string_view description={}) |
| RegisterHeldCommand without an icon. | |
| CommandID | FindCommand (CommandMode mode, KeyCode key, KeyModifier modifiers) const |
| The single-key command bound to (mode, key, modifiers); Invalid if none. | |
| CommandID | FindChord (CommandMode mode, KeyCode k1, KeyModifier m1, KeyCode k2, KeyModifier m2) const |
| The chord command in mode bound to exactly k1+m1 then k2+m2; Invalid if none. | |
| CommandID | RegisterChord (CommandMode mode, KeyCode key1, KeyModifier mods1, KeyCode key2, KeyModifier mods2, std::function< void()> callback, std::string_view description={}) |
| Registers a 2-key chord command (e.g. | |
| EventHandler | MakeHandler () |
| An EventHandler to push onto the InputManager as a global handler. | |
| const std::vector< Command > & | GetCommands () const |
| Every command, in registration order: the one at index i has CommandID{ i + 1 }. | |
| const Command * | GetCommand (CommandID id) const |
| The command, or null for an invalid or unknown ID. | |
| const std::vector< CommandID > & | GetCommandsForMode (CommandMode mode) const |
| Handles for a given mode, in registration order. | |
| void | BeginRebind (CommandID id) |
| Makes the next non-modifier keydown the shortcut of id instead of firing anything. | |
| void | CancelRebind () |
| bool | IsRebinding () const |
| CommandID | RebindTarget () const |
| void | SetShortcut (CommandID id, KeyCode key, KeyModifier modifiers) |
| Gives id the shortcut (key, modifiers), as a rebind does: another command in its mode that had it is left without one. | |
| void | ResetShortcuts () |
| Gives every command the shortcut it was registered with back (a chord, its first key) and cancels a rebind in progress: Reset to defaults. | |
| bool | IsChordPending () const |
| True while a chord prefix was pressed and awaits its second key. | |
| bool | ProcessInput (const InputState &state) |
| Runs a keydown InputState through rebind / chord / shortcut dispatch; true when it handled the key. | |
| bool | ProcessKeyUp (const InputState &state) |
| Fires onEnd of every active held command on the released key (modifiers are ignored); true if any fired. | |
Static Public Member Functions | |
| static CommandID | IDAt (size_t index) |
| static size_t | IndexOf (CommandID id) |
| static std::string | FormatChordShortcut (KeyCode k1, KeyModifier m1, KeyCode k2, KeyModifier m2) |
| Formats a chord shortcut as "Ctrl K, Ctrl S": its steps apart by a comma, as each step's keys are by spaces. | |
| static std::string | FormatShortcut (KeyCode key, KeyModifier modifiers) |
| Formats a (key, modifiers) combo as a human-readable string like "Ctrl Shift D". | |
| static void | ShortcutKeys (KeyCode key, KeyModifier modifiers, std::vector< std::string > &out) |
| Appends the names of a (key, modifiers) combo's keys to out, one per key as a keycap shows them: the modifiers, then the key ("Ctrl", "Shift", "D"). | |
| static std::string | KeyCodeName (KeyCode k) |
| A short human-readable key name, e.g. | |
Registry of commands: named actions with an optional icon and an optional shortcut key, each firing one callback when invoked (clicked from a menu / toolbar, or via its key).
Commands are organized by named modes.
Modes are registered by name and return an opaque CommandMode:
CommandMode sculpt = commandManager.RegisterMode("Sculpt");
commandManager.RegisterCommand(sculpt, KeyCode::KeyG, KeyModifier::None, []{ ... }, "Grab");
A command may have no shortcut key (KeyCode::None): it never dispatches from the keyboard but is still listed in the panel, where the user can bind a key.
Runs as a global InputManager handler (MakeHandler), so focused controls, a focused text editor and state.consumed all take keys first.
Shortcut lookup order: active mode first, then Default as fallback.
|
inline |
|
inline |
The app's undo history (text fields push their edits to it).
|
inline |
|
inline |
Registers a named mode and returns the CommandMode to use when registering commands or calling SetMode.
Registering the same name twice returns the existing value.
|
inline |
The name mode was registered with; empty for an unknown mode.
|
inline |
|
inline |
Makes mode the active mode, whose shortcuts are tried before Default.
Cancels any pending chord prefix.
|
inline |
|
inline |
Registers callback in mode; description names it in menus and shortcut lists.
key may be KeyCode::None (menu / toolbar only). Re-registering an existing (mode, key, modifiers) updates that command in place instead of adding one that could never dispatch. No-shortcut commands never collide.
|
inline |
RegisterCommand in the Default mode.
|
inline |
RegisterCommand without an icon.
|
inline |
RegisterCommand in the Default mode, without an icon.
|
inline |
RegisterCommand without a shortcut key.
|
inline |
RegisterCommand in the Default mode, without a shortcut key.
|
inline |
Registers a hold-to-act command (pan, orbit): onBegin on press, onEnd on release.
Single-key only; OS key-repeat doesn't re-fire onBegin. Otherwise as RegisterCommand.
|
inline |
RegisterHeldCommand in the Default mode, without an icon.
|
inline |
RegisterHeldCommand without an icon.
|
inline |
The single-key command bound to (mode, key, modifiers); Invalid if none.
Does not fall back to Default and does not match chords.
|
inline |
The chord command in mode bound to exactly k1+m1 then k2+m2; Invalid if none.
|
inline |
Registers a 2-key chord command (e.g.
Ctrl+K then Ctrl+S). Re-registering the same sequence updates it in place. A single-key command sharing the first key always wins at dispatch, so treat them as mutually exclusive.
|
inline |
An EventHandler to push onto the InputManager as a global handler.
KeyDown drives single-key / chord / rebind dispatch (and the begin of a held command); KeyUp drives the end of held commands.
|
inline |
Every command, in registration order: the one at index i has CommandID{ i + 1 }.
|
inlinestatic |
|
inlinestatic |
The command, or null for an invalid or unknown ID.
|
inline |
Handles for a given mode, in registration order.
|
inline |
Makes the next non-modifier keydown the shortcut of id instead of firing anything.
Escape cancels.
|
inline |
|
inline |
|
inline |
|
inline |
Gives id the shortcut (key, modifiers), as a rebind does: another command in its mode that had it is left without one.
KeyCode::None leaves it without one. For a chord, sets its first key.
|
inline |
Gives every command the shortcut it was registered with back (a chord, its first key) and cancels a rebind in progress: Reset to defaults.
|
inline |
True while a chord prefix was pressed and awaits its second key.
|
inlinestatic |
Formats a chord shortcut as "Ctrl K, Ctrl S": its steps apart by a comma, as each step's keys are by spaces.
The single-key form when k2 is None, "(unbound)" when k1 is None.
|
inlinestatic |
Formats a (key, modifiers) combo as a human-readable string like "Ctrl Shift D".
The keys are apart by spaces, so a key that is itself a "+" or "-" reads as such: "Ctrl +". An unbound shortcut (KeyCode::None) renders as "(unbound)" regardless of modifiers.
|
inlinestatic |
Appends the names of a (key, modifiers) combo's keys to out, one per key as a keycap shows them: the modifiers, then the key ("Ctrl", "Shift", "D").
A key whose name has a space is one name ("Num +"). Nothing for KeyCode::None.
|
inlinestatic |
A short human-readable key name, e.g.
"A", "F5", "Enter", "[", "Num +" (the numeric keypad's); "(unknown)" for a key without one (the "?" key is "?").
|
inline |
Runs a keydown InputState through rebind / chord / shortcut dispatch; true when it handled the key.
Public so tests and synthesized events can bypass MakeHandler.
|
inline |
Fires onEnd of every active held command on the released key (modifiers are ignored); true if any fired.
Public like ProcessInput.