pub struct KeyBinding {
pub code: KeyCode,
pub modifiers: KeyModifiers,
}Expand description
Represents a keyboard shortcut consisting of a key code and optional modifiers.
KeyBinding can be created from:
- A
KeyCodedirectly (no modifiers) - A
char(uppercase letters automatically include Shift modifier) - A
KeyEventreference
§Example
ⓘ
// Simple character key
let key: KeyBinding = 'j'.into();
// With modifiers
let ctrl_c = KeyBinding::ctrl('c');
let shift_tab = KeyBinding::new(KeyCode::Tab, KeyModifiers::SHIFT);
// Uppercase automatically includes Shift
let shift_h: KeyBinding = 'H'.into();Fields§
§code: KeyCode§modifiers: KeyModifiersImplementations§
Source§impl KeyBinding
impl KeyBinding
pub fn new(code: KeyCode, modifiers: KeyModifiers) -> Self
pub fn key(code: KeyCode) -> Self
pub fn ctrl(c: char) -> Self
pub fn alt(c: char) -> Self
pub fn shift(c: char) -> Self
Sourcepub fn display_compact(&self) -> String
pub fn display_compact(&self) -> String
Returns a compact display string using symbols for modifiers.
- Shift →
⇧ - Ctrl →
⌃ - Alt →
⌥
Examples: ⇧Tab, ⌃c, ⌥x, ⇧H
pub fn display(&self) -> String
Trait Implementations§
Source§impl Clone for KeyBinding
impl Clone for KeyBinding
impl Copy for KeyBinding
Source§impl Debug for KeyBinding
impl Debug for KeyBinding
Source§impl Display for KeyBinding
impl Display for KeyBinding
impl Eq for KeyBinding
Source§impl From<&KeyEvent> for KeyBinding
impl From<&KeyEvent> for KeyBinding
Source§impl From<KeyCode> for KeyBinding
impl From<KeyCode> for KeyBinding
Source§impl From<char> for KeyBinding
impl From<char> for KeyBinding
Source§impl Hash for KeyBinding
impl Hash for KeyBinding
Source§impl PartialEq for KeyBinding
impl PartialEq for KeyBinding
impl StructuralPartialEq for KeyBinding
Auto Trait Implementations§
impl Forget for KeyBinding
impl Freeze for KeyBinding
impl RefUnwindSafe for KeyBinding
impl Send for KeyBinding
impl Sync for KeyBinding
impl Unpin for KeyBinding
impl UnsafeUnpin for KeyBinding
impl UnwindSafe for KeyBinding
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,
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
Compare self to
key and return true if they are equal.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 moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more