Skip to main content

InputRouter

Struct InputRouter 

Source
pub struct InputRouter<A: Clone> { /* private fields */ }
Expand description

Routes key events through captured, focused, and global keymaps.

Resolution order is:

  1. Captured scopes, newest first.
  2. Bindings for the current focused component.
  3. Global bindings.

Exclusive captures stop routing when they do not handle a key, which is useful for blocking modals. Passthrough captures let unhandled keys continue to older layers, which is useful for temporary modes or non-blocking overlays.

Implementations§

Source§

impl<A: Clone> InputRouter<A>

Source

pub fn new() -> Self

Create an empty input router.

Source

pub fn bind_global(self, key: KeyBinding, action: A, description: &str) -> Self

Add a global binding and return the router.

Source

pub fn bind_focus( self, id: FocusId, key: KeyBinding, action: A, description: &str, ) -> Self

Add a focused component binding and return the router.

Source

pub fn bind_scope<S>( self, scope: S, key: KeyBinding, action: A, description: &str, ) -> Self
where S: Into<InputScope>,

Add a named or focus-scope binding and return the router.

Source

pub fn register_global(&mut self, key: KeyBinding, action: A, description: &str)

Register a global binding.

Source

pub fn register_focus( &mut self, id: FocusId, key: KeyBinding, action: A, description: &str, )

Register a binding for a focusable component.

Source

pub fn register_scope<S>( &mut self, scope: S, key: KeyBinding, action: A, description: &str, )
where S: Into<InputScope>,

Register a binding for a named or focus scope.

Source

pub fn push_capture<S>(&mut self, scope: S)
where S: Into<InputScope>,

Push an exclusive capture for a scope.

Source

pub fn push_capture_with_mode<S>(&mut self, scope: S, mode: InputCaptureMode)
where S: Into<InputScope>,

Push a capture with explicit unhandled-key behavior.

Source

pub fn pop_capture(&mut self) -> Option<InputCapture>

Remove the newest capture and return it.

Source

pub fn remove_capture<S>(&mut self, scope: S) -> bool
where S: Into<InputScope>,

Remove the newest capture for a scope.

Source

pub fn clear_captures(&mut self)

Remove all active captures.

Source

pub fn active_capture(&self) -> Option<&InputCapture>

Return the currently active capture, if any.

Source

pub fn resolve_key( &self, key: &KeyEvent, focused: Option<FocusId>, ) -> Option<RoutedInput<A>>

Resolve a key event against the current captures, focus, and globals.

Source

pub fn resolve_event( &self, event: &Event, focused: Option<FocusId>, ) -> Option<RoutedInput<A>>

Resolve a terminal event. Non-key events are ignored.

Source

pub fn global_help(&self) -> Vec<(String, String)>

Help entries for global bindings.

Source

pub fn focus_help(&self, id: FocusId) -> Vec<(String, String)>

Help entries for a focusable component.

Source

pub fn scope_help<S>(&self, scope: S) -> Vec<(String, String)>
where S: Into<InputScope>,

Help entries for a named or focus scope.

Source

pub fn active_help(&self, focused: Option<FocusId>) -> Vec<InputHelpEntry>

Help entries in the same order that key routing would consider them.

Trait Implementations§

Source§

impl<A: Clone> Default for InputRouter<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<A> Freeze for InputRouter<A>

§

impl<A> RefUnwindSafe for InputRouter<A>
where A: RefUnwindSafe,

§

impl<A> Send for InputRouter<A>
where A: Send,

§

impl<A> Sync for InputRouter<A>
where A: Sync,

§

impl<A> Unpin for InputRouter<A>
where A: Unpin,

§

impl<A> UnsafeUnpin for InputRouter<A>

§

impl<A> UnwindSafe for InputRouter<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.