Widget

Trait Widget 

Source
pub trait Widget: Send + 'static {
    // Required methods
    fn id(&self) -> &'static str;
    fn is_active(&self) -> bool;
    fn handle_key(
        &mut self,
        key: KeyEvent,
        ctx: &WidgetKeyContext<'_>,
    ) -> WidgetKeyResult;
    fn render(&mut self, frame: &mut Frame<'_>, area: Rect, theme: &Theme);
    fn as_any(&self) -> &dyn Any;
    fn as_any_mut(&mut self) -> &mut dyn Any;
    fn into_any(self: Box<Self>) -> Box<dyn Any>;

    // Provided methods
    fn priority(&self) -> u8 { ... }
    fn required_height(&self, available: u16) -> u16 { ... }
    fn blocks_input(&self) -> bool { ... }
    fn is_overlay(&self) -> bool { ... }
}
Expand description

Trait for registerable TUI widgets

Widgets that implement this trait can be registered with the App and will receive key events and rendering opportunities based on their state.

Required Methods§

Source

fn id(&self) -> &'static str

Unique identifier for this widget type

Source

fn is_active(&self) -> bool

Whether the widget is currently active/visible

Source

fn handle_key( &mut self, key: KeyEvent, ctx: &WidgetKeyContext<'_>, ) -> WidgetKeyResult

Handle key event, return result indicating what action to take.

The ctx parameter provides access to the theme and a navigation helper that respects configured key bindings.

Source

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

Render the widget

Source

fn as_any(&self) -> &dyn Any

Cast to Any for downcasting

Source

fn as_any_mut(&mut self) -> &mut dyn Any

Cast to Any for mutable downcasting

Source

fn into_any(self: Box<Self>) -> Box<dyn Any>

Convert to Box<dyn Any> for owned downcasting

Provided Methods§

Source

fn priority(&self) -> u8

Priority for key event handling (higher = checked first)

Modal widgets should have high priority to intercept input. Default is 100.

Source

fn required_height(&self, available: u16) -> u16

Calculate required height for this widget

Returns 0 if the widget doesn’t need dedicated space.

Source

fn blocks_input(&self) -> bool

Whether this widget blocks input to the text input when active

Source

fn is_overlay(&self) -> bool

Whether this widget is a full-screen overlay

Overlay widgets are rendered on top of everything else.

Implementors§