Skip to main content

ShortcutManager

Struct ShortcutManager 

Source
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>

Source

pub fn new(global: Arc<RwLock<ShortcutMap<C>>>) -> Self

Source

pub fn push_scope(&mut self, scope: ShortcutScope<C>)

Pushes a new scope onto the stack. Scopes are checked top-to-bottom during dispatch.

Source

pub fn pop_scope(&mut self)

Removes the top scope from the stack.

Source

pub fn register_global(&mut self, sc: Shortcut, cmd: C)

Inserts or replaces a shortcut in the shared global map.

Source

pub fn dispatch(&self, ctx: &Context) -> Vec<CommandTriggered>
where C: Into<CommandId>,

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::wants_keyboard_input is true (i.e. a text-edit widget has focus) so that typing never fires shortcuts.

Source

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::wants_keyboard_input is true.

Source

pub fn dispatch_raw(&self, ctx: &Context) -> Vec<C>

Dispatch without converting to CommandTriggered — returns raw C values.

Returns an empty Vec when Context::wants_keyboard_input is true.

Auto Trait Implementations§

§

impl<C> Freeze for ShortcutManager<C>

§

impl<C> !RefUnwindSafe for ShortcutManager<C>

§

impl<C> Send for ShortcutManager<C>
where C: Send + Sync,

§

impl<C> Sync for ShortcutManager<C>
where C: Send + Sync,

§

impl<C> Unpin for ShortcutManager<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for ShortcutManager<C>

§

impl<C> !UnwindSafe for ShortcutManager<C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.