Struct vizia_core::input::Keymap
source · pub struct Keymap<T>{ /* private fields */ }
Expand description
A keymap that associates key chords with actions.
This is useful if you have an application that lets the user configure their key chords. It allows you to check if a particular action is pressed rather than the actual keys. The relationship between a key chord and an action is a many-to-many relationship.
§Examples
First we need to create something that represents an action in our application. This is usually an enum.
#[derive(PartialEq, Copy, Clone)]
enum Action {
One,
Two,
Three,
}
Now we can create a new keymap inside of our application and configure our key chords.
We will bind Action::One
to the key chord A
, Action::Two
to the key chord CTRL+B
and Action::Three
to the key chord CTRL+SHIFT+C
. Every action has an associated callback
function that gets triggered when the key chord is pressed.
let keymap = Keymap::from(vec![
(KeyChord::new(Modifiers::empty(), Code::KeyA), KeymapEntry::new(Action::One, |_| debug!("Action One"))),
(KeyChord::new(Modifiers::CTRL, Code::KeyB), KeymapEntry::new(Action::Two, |_| debug!("Action Two"))),
(KeyChord::new(Modifiers::CTRL | Modifiers::SHIFT, Code::KeyC), KeymapEntry::new(Action::Three, |_| debug!("Action Three"))),
]);
Implementations§
source§impl<T> Keymap<T>
impl<T> Keymap<T>
sourcepub fn pressed_actions(
&self,
cx: &Context,
code: Code,
) -> impl Iterator<Item = &KeymapEntry<T>>
pub fn pressed_actions( &self, cx: &Context, code: Code, ) -> impl Iterator<Item = &KeymapEntry<T>>
Returns an iterator over every pressed keymap entry.
§Examples
for entry in keymap.pressed_actions(cx, Code::KeyA) {
debug!("The action {:?} is being pressed!", entry.action());
};
sourcepub fn export(&self) -> Vec<(&KeyChord, &KeymapEntry<T>)>
pub fn export(&self) -> Vec<(&KeyChord, &KeymapEntry<T>)>
Exports all keymap entries and their associated key chords.
This is useful if you want to have a settings window and need to access every key chord and keymap entry of a keymap.
§Examples
let actions_chords = keymap.export();
for (chord, entry) in actions_chords {
debug!("The key chord {:?} triggers the action {:?}!", chord, entry.action());
}
Trait Implementations§
source§impl<T> From<Vec<(KeyChord, KeymapEntry<T>)>> for Keymap<T>
impl<T> From<Vec<(KeyChord, KeymapEntry<T>)>> for Keymap<T>
source§fn from(vec: Vec<(KeyChord, KeymapEntry<T>)>) -> Self
fn from(vec: Vec<(KeyChord, KeymapEntry<T>)>) -> Self
Auto Trait Implementations§
impl<T> Freeze for Keymap<T>
impl<T> RefUnwindSafe for Keymap<T>where
T: RefUnwindSafe,
impl<T> Send for Keymap<T>
impl<T> Sync for Keymap<T>
impl<T> Unpin for Keymap<T>where
T: Unpin,
impl<T> UnwindSafe for Keymap<T>where
T: 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
§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.