pub struct NavigationHelper<'a> { /* private fields */ }Expand description
Helper for widgets to check navigation keys against configured bindings.
Pass this to widgets so they can respect configured key bindings instead of hardcoding key codes.
§Example
ⓘ
fn handle_key(&mut self, key: KeyEvent, ctx: &WidgetKeyContext) -> WidgetKeyResult {
if ctx.nav.is_move_up(&key) {
self.select_previous();
WidgetKeyResult::Handled
} else if ctx.nav.is_move_down(&key) {
self.select_next();
WidgetKeyResult::Handled
} else if ctx.nav.is_select(&key) {
// Handle selection
} else if ctx.nav.is_cancel(&key) {
// Handle cancel
} else {
WidgetKeyResult::NotHandled
}
}Implementations§
Sourcepub fn new(bindings: &'a KeyBindings) -> Self
pub fn new(bindings: &'a KeyBindings) -> Self
Create a new navigation helper from key bindings.
Sourcepub fn is_move_up(&self, key: &KeyEvent) -> bool
pub fn is_move_up(&self, key: &KeyEvent) -> bool
Check if the key matches the move up binding.
Sourcepub fn is_move_down(&self, key: &KeyEvent) -> bool
pub fn is_move_down(&self, key: &KeyEvent) -> bool
Check if the key matches the move down binding.
Sourcepub fn is_move_left(&self, key: &KeyEvent) -> bool
pub fn is_move_left(&self, key: &KeyEvent) -> bool
Check if the key matches the move left binding.
Sourcepub fn is_move_right(&self, key: &KeyEvent) -> bool
pub fn is_move_right(&self, key: &KeyEvent) -> bool
Check if the key matches the move right binding.
Sourcepub fn is_select(&self, key: &KeyEvent) -> bool
pub fn is_select(&self, key: &KeyEvent) -> bool
Check if the key matches the select binding (Enter, Space).
Auto Trait Implementations§
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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