Skip to main content

Widget

Trait Widget 

Source
pub trait Widget {
    // Required methods
    fn bounds(&self) -> Rect;
    fn set_bounds(&mut self, bounds: Rect);
    fn render(&self, buffer: &mut Buffer);
    fn handle_input(&mut self, event: &InputEvent) -> bool;
    fn needs_redraw(&self) -> bool;
    fn clear_redraw(&mut self);
}
Expand description

A UI component that can be rendered to a buffer and handle input.

All widgets implement this trait, allowing them to be composed into complex layouts and handled uniformly by the rendering system.

Required Methods§

Source

fn bounds(&self) -> Rect

Get the current bounds of this widget.

Source

fn set_bounds(&mut self, bounds: Rect)

Set the bounds of this widget.

Called when the layout changes (e.g., terminal resize).

Source

fn render(&self, buffer: &mut Buffer)

Render this widget to the given buffer.

The widget should only write to cells within its bounds.

Source

fn handle_input(&mut self, event: &InputEvent) -> bool

Handle an input event.

Returns true if the event was consumed by this widget, false if it should propagate to other widgets.

Source

fn needs_redraw(&self) -> bool

Check if this widget needs to be redrawn.

Source

fn clear_redraw(&mut self)

Clear the redraw flag after rendering.

Implementors§