pub struct Keybindings { /* private fields */ }Expand description
A registry of keyboard shortcuts mapped to actions for different widgets.
Keybindings manages the association between key combinations and their
corresponding actions, scoped by widget ID. It supports:
- Single key bindings via
bind - Multiple keys for the same action via
bind_many - Catch-all handlers via
bind_any
§Example
ⓘ
let mut kb = Keybindings::new();
kb.bind(WidgetId("list"), 'j', "Down", |world| { /* move down */ });
kb.bind_many(WidgetId("list"), keys![KeyCode::Up, 'k'], "Up", |world| { /* move up */ });Implementations§
Source§impl Keybindings
impl Keybindings
pub fn new() -> Self
pub fn bind( &mut self, id: WidgetId, key: impl Into<KeyBinding>, name: &'static str, action: impl Fn(&mut World) + Send + Sync + 'static, )
Sourcepub fn bind_many(
&mut self,
id: WidgetId,
keys: impl Into<Keys>,
name: &'static str,
action: impl Fn(&mut World) + Send + Sync + Clone + 'static,
)
pub fn bind_many( &mut self, id: WidgetId, keys: impl Into<Keys>, name: &'static str, action: impl Fn(&mut World) + Send + Sync + Clone + 'static, )
Binds multiple keys to the same action.
Sourcepub fn bind_any(
&mut self,
id: WidgetId,
handler: impl Fn(&mut World, &KeyBinding) + Send + Sync + 'static,
)
pub fn bind_any( &mut self, id: WidgetId, handler: impl Fn(&mut World, &KeyBinding) + Send + Sync + 'static, )
Binds a handler that fires for any key press on the given widget when no specific binding matches.
pub fn handle( &self, key: &KeyBinding, world: &mut World, ids: &[WidgetId], ) -> bool
Sourcepub fn display_for(&self, ids: &[WidgetId]) -> Vec<DisplayInfo>
pub fn display_for(&self, ids: &[WidgetId]) -> Vec<DisplayInfo>
Returns keybindings grouped by name for the given widget IDs. Keys with the same name and widget ID are grouped together.
Sourcepub fn display_all(&self) -> Vec<DisplayInfo>
pub fn display_all(&self) -> Vec<DisplayInfo>
Returns all keybindings grouped by name. Keys with the same name and widget ID are grouped together.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Keybindings
impl !UnwindSafe for Keybindings
impl Forget for Keybindings
impl Freeze for Keybindings
impl Send for Keybindings
impl Sync for Keybindings
impl Unpin for Keybindings
impl UnsafeUnpin for Keybindings
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> 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