TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::CommandManager Class Reference

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.
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"; the single-key form when k2 is None, "(unbound)" when k1 is None.
static std::string FormatShortcut (KeyCode key, KeyModifier modifiers)
 Formats a (key, modifiers) combo as a human-readable string like "Ctrl+Shift+D".
static std::string KeyCodeName (KeyCode k)
 A short human-readable key name, e.g. "A", "F5", "Enter", "["; "?" for unknown keys.

Detailed Description

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.

Constructor & Destructor Documentation

◆ CommandManager()

tachyon::CommandManager::CommandManager ( )
inline

Member Function Documentation

◆ History() [1/2]

UndoHistory & tachyon::CommandManager::History ( )
inline

The app's undo history (text fields push their edits to it).

◆ History() [2/2]

const UndoHistory & tachyon::CommandManager::History ( ) const
inline

◆ RegisterMode()

CommandMode tachyon::CommandManager::RegisterMode ( std::string_view name)
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.

◆ GetModeName()

std::string_view tachyon::CommandManager::GetModeName ( CommandMode mode) const
inline

The name mode was registered with; empty for an unknown mode.

◆ GetModeCount()

uint32_t tachyon::CommandManager::GetModeCount ( ) const
inline

◆ SetMode()

void tachyon::CommandManager::SetMode ( CommandMode mode)
inline

Makes mode the active mode, whose shortcuts are tried before Default.

Cancels any pending chord prefix.

◆ GetMode()

CommandMode tachyon::CommandManager::GetMode ( ) const
inline

◆ RegisterCommand() [1/6]

CommandID tachyon::CommandManager::RegisterCommand ( CommandMode mode,
IconID icon,
KeyCode key,
KeyModifier modifiers,
std::function< void()> callback,
std::string_view description = {} )
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.

◆ RegisterCommand() [2/6]

CommandID tachyon::CommandManager::RegisterCommand ( IconID icon,
KeyCode key,
KeyModifier modifiers,
std::function< void()> callback,
std::string_view description = {} )
inline

RegisterCommand in the Default mode.

◆ RegisterCommand() [3/6]

CommandID tachyon::CommandManager::RegisterCommand ( CommandMode mode,
KeyCode key,
KeyModifier modifiers,
std::function< void()> callback,
std::string_view description = {} )
inline

RegisterCommand without an icon.

◆ RegisterCommand() [4/6]

CommandID tachyon::CommandManager::RegisterCommand ( KeyCode key,
KeyModifier modifiers,
std::function< void()> callback,
std::string_view description = {} )
inline

RegisterCommand in the Default mode, without an icon.

◆ RegisterCommand() [5/6]

CommandID tachyon::CommandManager::RegisterCommand ( CommandMode mode,
IconID icon,
std::function< void()> callback,
std::string_view description = {} )
inline

RegisterCommand without a shortcut key.

◆ RegisterCommand() [6/6]

CommandID tachyon::CommandManager::RegisterCommand ( IconID icon,
std::function< void()> callback,
std::string_view description = {} )
inline

RegisterCommand in the Default mode, without a shortcut key.

◆ RegisterHeldCommand() [1/3]

CommandID tachyon::CommandManager::RegisterHeldCommand ( CommandMode mode,
IconID icon,
KeyCode key,
KeyModifier modifiers,
std::function< void()> onBegin,
std::function< void()> onEnd,
std::string_view description = {} )
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.

◆ RegisterHeldCommand() [2/3]

CommandID tachyon::CommandManager::RegisterHeldCommand ( KeyCode key,
KeyModifier modifiers,
std::function< void()> onBegin,
std::function< void()> onEnd,
std::string_view description = {} )
inline

RegisterHeldCommand in the Default mode, without an icon.

◆ RegisterHeldCommand() [3/3]

CommandID tachyon::CommandManager::RegisterHeldCommand ( CommandMode mode,
KeyCode key,
KeyModifier modifiers,
std::function< void()> onBegin,
std::function< void()> onEnd,
std::string_view description = {} )
inline

RegisterHeldCommand without an icon.

◆ FindCommand()

CommandID tachyon::CommandManager::FindCommand ( CommandMode mode,
KeyCode key,
KeyModifier modifiers ) const
inline

The single-key command bound to (mode, key, modifiers); Invalid if none.

Does not fall back to Default and does not match chords.

◆ FindChord()

CommandID tachyon::CommandManager::FindChord ( CommandMode mode,
KeyCode k1,
KeyModifier m1,
KeyCode k2,
KeyModifier m2 ) const
inline

The chord command in mode bound to exactly k1+m1 then k2+m2; Invalid if none.

◆ RegisterChord()

CommandID tachyon::CommandManager::RegisterChord ( CommandMode mode,
KeyCode key1,
KeyModifier mods1,
KeyCode key2,
KeyModifier mods2,
std::function< void()> callback,
std::string_view description = {} )
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.

◆ MakeHandler()

EventHandler tachyon::CommandManager::MakeHandler ( )
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.

◆ GetCommands()

const std::vector< Command > & tachyon::CommandManager::GetCommands ( ) const
inline

Every command, in registration order: the one at index i has CommandID{ i + 1 }.

◆ IDAt()

CommandID tachyon::CommandManager::IDAt ( size_t index)
inlinestatic

◆ IndexOf()

size_t tachyon::CommandManager::IndexOf ( CommandID id)
inlinestatic

◆ GetCommand()

const Command * tachyon::CommandManager::GetCommand ( CommandID id) const
inline

The command, or null for an invalid or unknown ID.

◆ GetCommandsForMode()

const std::vector< CommandID > & tachyon::CommandManager::GetCommandsForMode ( CommandMode mode) const
inline

Handles for a given mode, in registration order.

◆ BeginRebind()

void tachyon::CommandManager::BeginRebind ( CommandID id)
inline

Makes the next non-modifier keydown the shortcut of id instead of firing anything.

Escape cancels.

◆ CancelRebind()

void tachyon::CommandManager::CancelRebind ( )
inline

◆ IsRebinding()

bool tachyon::CommandManager::IsRebinding ( ) const
inline

◆ RebindTarget()

CommandID tachyon::CommandManager::RebindTarget ( ) const
inline

◆ SetShortcut()

void tachyon::CommandManager::SetShortcut ( CommandID id,
KeyCode key,
KeyModifier modifiers )
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.

◆ IsChordPending()

bool tachyon::CommandManager::IsChordPending ( ) const
inline

True while a chord prefix was pressed and awaits its second key.

◆ FormatChordShortcut()

std::string tachyon::CommandManager::FormatChordShortcut ( KeyCode k1,
KeyModifier m1,
KeyCode k2,
KeyModifier m2 )
inlinestatic

Formats a chord shortcut as "Ctrl+K Ctrl+S"; the single-key form when k2 is None, "(unbound)" when k1 is None.

◆ FormatShortcut()

std::string tachyon::CommandManager::FormatShortcut ( KeyCode key,
KeyModifier modifiers )
inlinestatic

Formats a (key, modifiers) combo as a human-readable string like "Ctrl+Shift+D".

An unbound shortcut (KeyCode::None) renders as "(unbound)" regardless of modifiers.

◆ KeyCodeName()

std::string tachyon::CommandManager::KeyCodeName ( KeyCode k)
inlinestatic

A short human-readable key name, e.g. "A", "F5", "Enter", "["; "?" for unknown keys.

◆ ProcessInput()

bool tachyon::CommandManager::ProcessInput ( const InputState & state)
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.

◆ ProcessKeyUp()

bool tachyon::CommandManager::ProcessKeyUp ( const InputState & state)
inline

Fires onEnd of every active held command on the released key (modifiers are ignored); true if any fired.

Public like ProcessInput.


The documentation for this class was generated from the following file: