pub struct InputRouter<A: Clone> { /* private fields */ }Expand description
Routes key events through captured, focused, and global keymaps.
Resolution order is:
- Captured scopes, newest first.
- Bindings for the current focused component.
- 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>
impl<A: Clone> InputRouter<A>
Sourcepub fn bind_global(self, key: KeyBinding, action: A, description: &str) -> Self
pub fn bind_global(self, key: KeyBinding, action: A, description: &str) -> Self
Add a global binding and return the router.
Sourcepub fn bind_focus(
self,
id: FocusId,
key: KeyBinding,
action: A,
description: &str,
) -> Self
pub fn bind_focus( self, id: FocusId, key: KeyBinding, action: A, description: &str, ) -> Self
Add a focused component binding and return the router.
Sourcepub fn bind_scope<S>(
self,
scope: S,
key: KeyBinding,
action: A,
description: &str,
) -> Selfwhere
S: Into<InputScope>,
pub fn bind_scope<S>(
self,
scope: S,
key: KeyBinding,
action: A,
description: &str,
) -> Selfwhere
S: Into<InputScope>,
Add a named or focus-scope binding and return the router.
Sourcepub fn register_global(&mut self, key: KeyBinding, action: A, description: &str)
pub fn register_global(&mut self, key: KeyBinding, action: A, description: &str)
Register a global binding.
Sourcepub fn register_focus(
&mut self,
id: FocusId,
key: KeyBinding,
action: A,
description: &str,
)
pub fn register_focus( &mut self, id: FocusId, key: KeyBinding, action: A, description: &str, )
Register a binding for a focusable component.
Sourcepub fn register_scope<S>(
&mut self,
scope: S,
key: KeyBinding,
action: A,
description: &str,
)where
S: Into<InputScope>,
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.
Sourcepub fn push_capture<S>(&mut self, scope: S)where
S: Into<InputScope>,
pub fn push_capture<S>(&mut self, scope: S)where
S: Into<InputScope>,
Push an exclusive capture for a scope.
Sourcepub fn push_capture_with_mode<S>(&mut self, scope: S, mode: InputCaptureMode)where
S: Into<InputScope>,
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.
Sourcepub fn pop_capture(&mut self) -> Option<InputCapture>
pub fn pop_capture(&mut self) -> Option<InputCapture>
Remove the newest capture and return it.
Sourcepub fn remove_capture<S>(&mut self, scope: S) -> boolwhere
S: Into<InputScope>,
pub fn remove_capture<S>(&mut self, scope: S) -> boolwhere
S: Into<InputScope>,
Remove the newest capture for a scope.
Sourcepub fn clear_captures(&mut self)
pub fn clear_captures(&mut self)
Remove all active captures.
Sourcepub fn active_capture(&self) -> Option<&InputCapture>
pub fn active_capture(&self) -> Option<&InputCapture>
Return the currently active capture, if any.
Sourcepub fn resolve_key(
&self,
key: &KeyEvent,
focused: Option<FocusId>,
) -> Option<RoutedInput<A>>
pub fn resolve_key( &self, key: &KeyEvent, focused: Option<FocusId>, ) -> Option<RoutedInput<A>>
Resolve a key event against the current captures, focus, and globals.
Sourcepub fn resolve_event(
&self,
event: &Event,
focused: Option<FocusId>,
) -> Option<RoutedInput<A>>
pub fn resolve_event( &self, event: &Event, focused: Option<FocusId>, ) -> Option<RoutedInput<A>>
Resolve a terminal event. Non-key events are ignored.
Sourcepub fn global_help(&self) -> Vec<(String, String)>
pub fn global_help(&self) -> Vec<(String, String)>
Help entries for global bindings.
Sourcepub fn focus_help(&self, id: FocusId) -> Vec<(String, String)>
pub fn focus_help(&self, id: FocusId) -> Vec<(String, String)>
Help entries for a focusable component.
Sourcepub fn scope_help<S>(&self, scope: S) -> Vec<(String, String)>where
S: Into<InputScope>,
pub fn scope_help<S>(&self, scope: S) -> Vec<(String, String)>where
S: Into<InputScope>,
Help entries for a named or focus scope.
Sourcepub fn active_help(&self, focused: Option<FocusId>) -> Vec<InputHelpEntry>
pub fn active_help(&self, focused: Option<FocusId>) -> Vec<InputHelpEntry>
Help entries in the same order that key routing would consider them.