Enum Key
pub enum Key<C = SmolStr> {
Named(Named),
Character(C),
Unidentified,
}Expand description
A key on the keyboard.
This is mostly the Key type found in winit.
Variants§
Named(Named)
A key with an established name.
Character(C)
A key string that corresponds to the character typed by the user, taking into account the user’s current locale setting, and any system-level keyboard mapping overrides that are in effect.
Unidentified
An unidentified key.
Implementations§
§impl Key
impl Key
pub fn as_ref(&self) -> Key<&str>
pub fn as_ref(&self) -> Key<&str>
Convert Key::Character(SmolStr) to Key::Character(&str) so you can more easily match on
Key. All other variants remain unchanged.
pub fn to_latin(&self, physical_key: Physical) -> Option<char>
pub fn to_latin(&self, physical_key: Physical) -> Option<char>
Tries to convert this logical Key into its latin character, using the
Physical key provided for translation if it isn’t already in latin.
Returns None if no latin variant could be found.
use iced_core::keyboard::key::{Key, Named, Physical, Code};
// Latin c
assert_eq!(
Key::Character("c".into()).to_latin(Physical::Code(Code::KeyC)),
Some('c'),
);
// Cyrillic с
assert_eq!(
Key::Character("с".into()).to_latin(Physical::Code(Code::KeyC)),
Some('c'),
);
// Arrow Left
assert_eq!(
Key::Named(Named::ArrowLeft).to_latin(Physical::Code(Code::ArrowLeft)),
None,
);Trait Implementations§
§impl<C> Ord for Key<C>where
C: Ord,
impl<C> Ord for Key<C>where
C: Ord,
§impl<C> PartialOrd for Key<C>where
C: PartialOrd,
impl<C> PartialOrd for Key<C>where
C: PartialOrd,
impl<C> Eq for Key<C>where
C: Eq,
impl<C> StructuralPartialEq for Key<C>
Auto Trait Implementations§
impl<C> Freeze for Key<C>where
C: Freeze,
impl<C> RefUnwindSafe for Key<C>where
C: RefUnwindSafe,
impl<C> Send for Key<C>where
C: Send,
impl<C> Sync for Key<C>where
C: Sync,
impl<C> Unpin for Key<C>where
C: Unpin,
impl<C> UnwindSafe for Key<C>where
C: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&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
Checks if this value is equivalent to the given key. Read more
§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
Compare self to
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
Checks if this value is equivalent to the given key. Read more
§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<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Turns some type into the initial state of some
Application.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>
Converts
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>
Converts
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