pub struct Accel {
pub code: KeyCode,
pub mods: KeyMods,
}Expand description
A keyboard shortcut, parsed out of the string an item declares.
The core binds nothing to it and never has (MenuItem::accel is
display); this exists for the one consumer that needs the parts rather
than the words — a platform menu bar, which sets a real key equivalent
and then matches it before the window ever sees the key.
Both spellings parse, because both are written in the field: the
portable one ("mod+shift+s", where mod is Command on macOS and
Control elsewhere) and the platform one a menu is read in ("⇧⌘S",
"Ctrl+Shift+S"). Accel::display is the second, which is what
declare_menu_bar normalizes a declaration into so the drawn bar and
the platform’s read the same.
Fields§
§code: KeyCode§mods: KeyModsImplementations§
Source§impl Accel
impl Accel
Sourcepub fn parse(s: &str) -> Option<Accel>
pub fn parse(s: &str) -> Option<Accel>
Parses "mod+s", "ctrl+shift+p", "f5", "⇧⌘S". None for
anything this vocabulary cannot name — the caller then leaves the
string alone and draws it as written, since a shortcut kui cannot
parse is still a shortcut the app’s own keymap runs.
Sourcepub fn display(&self) -> String
pub fn display(&self) -> String
How the platform writes it: the macOS glyph run (⇧⌘S, in AppKit’s
order, no separators) or the spelled form (Ctrl+Shift+S).
Sourcepub fn spelling(&self) -> String
pub fn spelling(&self) -> String
The portable spelling, the one Accel::parse reads back to the
same chord on every platform: the modifiers held as ctrl,
super, alt, shift in that order, then the key by its wire
name ("ctrl+shift+i", "super+alt+f12"). What a binding hands
out when it reads a chord back; Accel::display is what a
person reads.
Sourcepub fn key_equivalent(&self) -> Option<String>
pub fn key_equivalent(&self) -> Option<String>
The key equivalent an NSMenuItem takes: the character, lowercased
(AppKit reads an uppercase one as Shift being held), or None for a
key AppKit spells with a function-key code this does not carry.
Trait Implementations§
impl Copy for Accel
impl Eq for Accel
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
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.