pub struct ShortcutManager<C> { /* private fields */ }Expand description
Scans egui key events each frame and returns triggered commands.
Lookup order: extra scope → scoped stack (top → bottom) → global. Non-consuming scopes continue propagation; consuming scopes stop lower scopes and the global map. Within one scope/map, the most specific logical shortcut wins.
Implementations§
Source§impl<C: Clone> ShortcutManager<C>
impl<C: Clone> ShortcutManager<C>
pub fn new(global: Arc<RwLock<ShortcutMap<C>>>) -> Self
Sourcepub fn push_scope(&mut self, scope: ShortcutScope<C>)
pub fn push_scope(&mut self, scope: ShortcutScope<C>)
Pushes a new scope onto the stack. Scopes are checked top-to-bottom during dispatch.
Sourcepub fn register_global(&mut self, sc: Shortcut, cmd: C)
pub fn register_global(&mut self, sc: Shortcut, cmd: C)
Inserts or replaces a shortcut in the shared global map.
Sourcepub fn fill_shortcut_hints<R>(&self, registry: &mut CommandRegistry<R>)
pub fn fill_shortcut_hints<R>(&self, registry: &mut CommandRegistry<R>)
Populates CommandRegistry shortcut hints from the global shortcut map.
For each (Shortcut, C) entry in the global map, formats the shortcut as a
human-readable string (e.g. "Ctrl+S", "F1") and writes it into the
corresponding [CommandSpec::shortcut_hint] in registry.
Commands that have a shortcut binding but are not registered in registry
are silently skipped. Commands registered in registry that have no
shortcut binding are left unchanged.
Sourcepub fn dispatch(&self, ctx: &Context) -> Vec<CommandTriggered>
pub fn dispatch(&self, ctx: &Context) -> Vec<CommandTriggered>
Scan egui key events and return all triggered commands this frame.
Matched key events are consumed from the egui input queue so that egui widgets don’t double-handle them.
Returns an empty Vec when Context::egui_wants_keyboard_input is true
(i.e. a text-edit widget has focus) so that typing never fires shortcuts.
Sourcepub fn dispatch_raw_with_extra(
&self,
ctx: &Context,
extra: Option<&ShortcutMap<C>>,
) -> Vec<C>
pub fn dispatch_raw_with_extra( &self, ctx: &Context, extra: Option<&ShortcutMap<C>>, ) -> Vec<C>
Dispatch with an optional extra scope checked before global shortcuts.
Use this when a context-specific shortcut map (e.g. editor scope) should
take priority without needing push_scope/pop_scope on a mutable static.
The extra scope is always consuming: a match there skips the global map.
Returns an empty Vec when Context::egui_wants_keyboard_input is true.
Sourcepub fn dispatch_raw(&self, ctx: &Context) -> Vec<C>
pub fn dispatch_raw(&self, ctx: &Context) -> Vec<C>
Dispatch without converting to CommandTriggered — returns raw C values.
Returns an empty Vec when Context::egui_wants_keyboard_input is true.
Sourcepub fn try_shortcut(&self, ctx: &Context, sc: Shortcut) -> Option<C>
pub fn try_shortcut(&self, ctx: &Context, sc: Shortcut) -> Option<C>
Check whether a specific shortcut was pressed this frame, consuming it if so.
Returns Some(cmd) if sc appears in the global shortcut map and was
pressed this frame; None otherwise.
Unlike [dispatch] / [dispatch_raw], this does not check
egui_wants_keyboard_input — use it only when you intentionally want to
intercept a key even while a text field has focus.