pub trait InputHandler {
// Required method
fn handle_key_event(
&mut self,
event: &KeyEvent,
ctx: &mut InputContext,
) -> InputResult;
// Provided methods
fn focused_child(&self) -> Option<&dyn InputHandler> { ... }
fn focused_child_mut(&mut self) -> Option<&mut dyn InputHandler> { ... }
fn is_modal(&self) -> bool { ... }
fn dispatch_input(
&mut self,
event: &KeyEvent,
ctx: &mut InputContext,
) -> InputResult { ... }
}Expand description
Trait for elements that can handle input events.
Implementors should:
- First delegate to
focused_child_mut()if it exists - Handle keys relevant to this element
- Return
ConsumedorIgnoredappropriately - Modal elements should return
Consumedfor unhandled keys
Required Methods§
Sourcefn handle_key_event(
&mut self,
event: &KeyEvent,
ctx: &mut InputContext,
) -> InputResult
fn handle_key_event( &mut self, event: &KeyEvent, ctx: &mut InputContext, ) -> InputResult
Handle a key event. Returns whether the event was consumed.
Provided Methods§
Sourcefn focused_child(&self) -> Option<&dyn InputHandler>
fn focused_child(&self) -> Option<&dyn InputHandler>
Get the currently focused child handler, if any.
Sourcefn focused_child_mut(&mut self) -> Option<&mut dyn InputHandler>
fn focused_child_mut(&mut self) -> Option<&mut dyn InputHandler>
Get the currently focused child handler mutably, if any.
Sourcefn dispatch_input(
&mut self,
event: &KeyEvent,
ctx: &mut InputContext,
) -> InputResult
fn dispatch_input( &mut self, event: &KeyEvent, ctx: &mut InputContext, ) -> InputResult
Dispatch input through this handler and its children. This is the main entry point - it handles the bubble-up logic.