Struct Keys
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,A–Z, 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 Digit0–Digit9, symbols like
Plus, Comma, etc.) automatically get Shift? behavior, just like the @keys macro.
Implementations§
§impl Keys
impl Keys
pub fn from_parts<'a>(
parts: impl IntoIterator<Item = &'a str>,
) -> Result<Keys, KeysParseError>
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§
§impl Display for Keys
impl Display for Keys
§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
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!
impl Eq for Keys
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> 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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.SharedString.