Skip to main content

Accel

Struct Accel 

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

Implementations§

Source§

impl Accel

Source

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.

Source

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).

Source

pub fn label(spelled: &str) -> Cow<'_, str>

What a menu draws for the accelerator spelled: its Accel::display when it parses, and spelled itself when it does not — a shortcut kui cannot name is still one the app’s own keymap runs, and its spelling is the app’s (ADR 0018, decision 7). The drawn menu, the drawn bar and open_menu all read an accelerator through this, so a portable "mod+shift+n" never reaches the screen as written (backlog F127).

Source

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.

Source

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§

Source§

impl Clone for Accel

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Accel

Source§

impl Debug for Accel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Accel

Source§

impl PartialEq for Accel

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.