Skip to main content

InputHandler

Trait InputHandler 

Source
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:

  1. First delegate to focused_child_mut() if it exists
  2. Handle keys relevant to this element
  3. Return Consumed or Ignored appropriately
  4. Modal elements should return Consumed for unhandled keys

Required Methods§

Source

fn handle_key_event( &mut self, event: &KeyEvent, ctx: &mut InputContext, ) -> InputResult

Handle a key event. Returns whether the event was consumed.

Provided Methods§

Source

fn focused_child(&self) -> Option<&dyn InputHandler>

Get the currently focused child handler, if any.

Source

fn focused_child_mut(&mut self) -> Option<&mut dyn InputHandler>

Get the currently focused child handler mutably, if any.

Source

fn is_modal(&self) -> bool

Whether this handler is modal (consumes all unhandled input).

Source

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.

Implementors§