Skip to main content

Keys

Struct Keys 

Source
pub struct Keys { /* private fields */ }
Expand description

The Keys type is the Rust representation of Slint’s keys primitive type.

It can be created with the @keys macro in Slint and defines which key event(s) activate a KeyBinding.

See also the Slint documentation on Key Bindings.

In .slint files, Keys values are typically created via the @keys(...) macro. From backend code, they can be created from a list of string parts with the similar syntax as the macro:

use i_slint_core::input::Keys;

let save = Keys::from_parts(["Control", "S"])?;
let undo = Keys::from_parts(["Control", "Shift?", "Z"])?;
let f5 = Keys::from_parts(["F5"])?;
let zoom_in = Keys::from_parts(["Control", "Plus"])?;
let euro = Keys::from_parts(["Control", "€"])?;
let empty = Keys::from_parts([])?;  // same as Keys::default()

§Parts format

Each element is either a modifier or a key (case-sensitive, matching the @keys macro):

  • Modifiers (optional): Control, Alt, Shift, Meta
  • Optional modifiers: Shift?, Alt? (match regardless of that modifier’s state)
  • Named key (required, exactly one): A named key (Return, Tab, F1, Plus, Space, AZ, etc.)
  • String literal fallback: If no named key matches, the part is treated as a string literal — it must be a single lowercase grapheme cluster (e.g., "€", "é")

Keys with layout-dependent shifted variants (digits Digit0Digit9, symbols like Plus, Comma, etc.) automatically get Shift? behavior, just like the @keys macro.

Implementations§

Source§

impl Keys

Source

pub fn from_parts<'a>( parts: impl IntoIterator<Item = &'a str>, ) -> Result<Keys, KeysParseError>

Create a Keys from an iterator of string parts (matching @keys macro syntax).

Each element is either a modifier (Control, Shift, Alt, Meta, Shift?, Alt?) or a key. Keys are first looked up by name (case-sensitive) in the Key namespace; if not found, treated as a string literal (must be a single lowercase grapheme cluster). Exactly one non-modifier key must be present.

An empty iterator returns Keys::default() (same as @keys()).

See also the Slint documentation on Key Bindings.

Note: This currently only supports a single shortcut (one key + modifiers).

Trait Implementations§

Source§

impl Clone for Keys

Source§

fn clone(&self) -> Keys

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 Debug for Keys

Source§

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

Formats the keyboard shortcut so that the output would be accepted by the @keys macro in Slint.

Source§

impl Default for Keys

Source§

fn default() -> Keys

Returns the “default value” for a type. Read more
Source§

impl Display for Keys

Source§

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

Converts the Keys to a string that looks native on the current platform.

For example, the shortcut created with @keys(Meta + Control + A) will be converted like this:

  • macOS: ⌃⌘A
  • Windows: Win+Ctrl+A
  • Linux: Super+Ctrl+A

Note that this functions output is best-effort and may be adjusted/improved at any time, do not rely on this output to be stable!

Source§

impl Eq for Keys

Source§

impl PartialEq for Keys

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Keys

Auto Trait Implementations§

§

impl Freeze for Keys

§

impl RefUnwindSafe for Keys

§

impl Send for Keys

§

impl Sync for Keys

§

impl Unpin for Keys

§

impl UnsafeUnpin for Keys

§

impl UnwindSafe for Keys

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> Brush for T
where T: Clone + PartialEq + Default + Debug,

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> ErasedDestructor for T
where T: 'static,

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> 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> ToSharedString for T
where T: Display + ?Sized,

Source§

fn to_shared_string(&self) -> SharedString

Converts the given value to a SharedString.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.