Skip to main content

Crate egui_command_binding

Crate egui_command_binding 

Source
Expand description

egui-command-binding — keyboard shortcut → CommandId dispatch for egui apps.

Wraps egui-command types with egui-specific input handling. ShortcutManager<C> scans egui Key events and returns a Vec<C> of triggered commands — it never executes business logic directly. When an application also keeps command metadata in CommandRegistry, ShortcutManager::fill_shortcut_hints can copy the global shortcut map into each registered egui_command::CommandSpec::shortcut_hint field so menus, toolbars, and help overlays show the same display text as the active bindings.

§Quick-start

// Define your command type (typically a C: From<CommandId> enum).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum AppCmd { ShowHelp, PrevProfile, NextProfile }

// Build the global map once (e.g. in a lazy_static):
let mut global: ShortcutMap<AppCmd> = ShortcutMap::new();
global.insert(shortcut("F1"),  AppCmd::ShowHelp);
global.insert(shortcut("F7"),  AppCmd::PrevProfile);
global.insert(shortcut("F8"),  AppCmd::NextProfile);

// Each frame, collect triggered commands:
let triggered = manager.dispatch(ctx);
for cmd in triggered { handle(cmd); }

// Optional: populate display-only shortcut hints in a command registry.
manager.fill_shortcut_hints(&mut registry);

Re-exports§

pub use egui_command;

Macros§

shortcut_map
Build a ShortcutMap from shortcut_string => command pairs.

Structs§

Shortcut
A keyboard shortcut: a key plus zero-or-more modifier keys.
ShortcutManager
Scans egui key events each frame and returns triggered commands.
ShortcutScope
A named, optionally-consuming scope of shortcuts.

Functions§

shortcut
Parse a shortcut string like "Ctrl+S", "F2", "Alt+Shift+X".

Type Aliases§

ShortcutMap
Maps Shortcut → C (an app-defined command value).