pub struct Accel {
pub mods: AccelMods,
pub key: Key,
}Expand description
A keyboard accelerator: a chord of modifier roles plus a key.
Build one with Accel::primary and the chainable shift /
alt / secondary builders, or parse the
conventional string form ("Ctrl+Shift+R", "Ctrl+Enter") via From<&str>
— in strings, Ctrl and Cmd both mean the primary role. Exotic
combinations without primary can be built from the public fields.
Fields§
§mods: AccelMods§key: KeyImplementations§
Source§impl Accel
impl Accel
Sourcepub fn primary(key: impl Into<Key>) -> Self
pub fn primary(key: impl Into<Key>) -> Self
A chord of the primary command modifier plus key — the everyday
accelerator: Accel::primary('r'), Accel::primary(NamedKey::Enter).
Sourcepub fn secondary(self) -> Self
pub fn secondary(self) -> Self
Add the secondary system modifier (⌃ on macOS, Super elsewhere) to the chord. Best-effort outside macOS — see the module docs.
Sourcepub fn matches(
&self,
key: Key,
modifiers: Modifiers,
scheme: ModifierScheme,
) -> bool
pub fn matches( &self, key: Key, modifiers: Modifiers, scheme: ModifierScheme, ) -> bool
Whether the pressed key + modifiers are exactly this chord under
scheme. Modifiers must match exactly (a Ctrl+R accel does not fire
on Ctrl+Shift+R); character keys compare case-insensitively. AltGr
chords never match — the right Alt composes characters (and Windows
reports it as Ctrl+Alt), so those keystrokes are text entry, not
commands.
Sourcepub fn label(&self, scheme: ModifierScheme) -> String
pub fn label(&self, scheme: ModifierScheme) -> String
The chord’s display label under scheme, e.g. "Ctrl+Shift+R" on PC
and "Shift+Cmd+R" on a Mac. Modifier order follows each platform’s
convention: Ctrl, Super, Alt, Shift on PC; Ctrl, Opt, Shift, Cmd
(Apple’s ⌃⌥⇧⌘) on macOS.
Trait Implementations§
impl Copy for Accel
impl Eq for Accel
Source§impl From<&str> for Accel
impl From<&str> for Accel
Source§fn from(s: &str) -> Self
fn from(s: &str) -> Self
Parse the conventional "Ctrl+Shift+R" string form. Modifier tokens
(case-insensitive): Ctrl / Cmd / Command / Primary → the
primary role; Super / Win / Secondary → secondary; Alt / Opt
/ Option → alt; Shift. The final token is the key: a single
character, or a named key (Enter, Esc, Left, PageUp, …).
§Panics
On malformed input. Accelerator strings are in practice compile-time constants, so a typo should fail loudly at first use, not bind nothing.
impl StructuralPartialEq for Accel
Auto Trait Implementations§
impl Freeze for Accel
impl RefUnwindSafe for Accel
impl Send for Accel
impl Sync for Accel
impl Unpin for Accel
impl UnsafeUnpin for Accel
impl UnwindSafe for Accel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.