Skip to main content

FocusableWidget

Trait FocusableWidget 

Source
pub trait FocusableWidget {
    // Required methods
    fn id(&self) -> WidgetId;
    fn handle_key(&self, key: KeyEvent) -> InputResult;
    fn handle_operation(
        &mut self,
        op: &Operation,
        settings: &Settings,
    ) -> Option<Event>;
    fn render(
        &self,
        frame: &mut Frame<'_>,
        area: Rect,
        focused: bool,
        theme: &Theme,
    );

    // Provided methods
    fn handle_mouse(&self, _mouse: MouseEvent, _area: Rect) -> InputResult { ... }
    fn captures_tab(&self) -> bool { ... }
    fn focusable(&self) -> bool { ... }
}
Expand description

A widget that can receive focus, handle input, and render itself.

This is NOT a replacement for ratatui’s Widget trait. It is a higher-level composition trait used by views to manage interactive sub-components. Widgets still use ratatui primitives internally.

Required Methods§

Source

fn id(&self) -> WidgetId

Unique id within this view’s focus ring.

Source

fn handle_key(&self, key: KeyEvent) -> InputResult

Handle a key event while this widget has focus. Returns ops + consumed flag. Must not mutate self.

Source

fn handle_operation( &mut self, op: &Operation, settings: &Settings, ) -> Option<Event>

Apply a single operation directed at this widget. Returns Some(event) if the operation was handled.

Source

fn render( &self, frame: &mut Frame<'_>, area: Rect, focused: bool, theme: &Theme, )

Render the widget into the given area. focused indicates whether this widget currently has focus (for styling: cursor visibility, border highlighting, etc.).

Provided Methods§

Source

fn handle_mouse(&self, _mouse: MouseEvent, _area: Rect) -> InputResult

Handle a mouse event. area is the widget’s last rendered rect.

Source

fn captures_tab(&self) -> bool

Whether this widget wants to capture Tab key presses, preventing the view from using Tab for focus cycling. Default: false. Override for multi-line text inputs.

Source

fn focusable(&self) -> bool

Whether this widget accepts focus at all. Default: true. Override for decorative-only widgets.

Implementors§