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§
Sourcefn set_bounds(&mut self, bounds: Rect)
fn set_bounds(&mut self, bounds: Rect)
Set the bounds of this widget.
Called when the layout changes (e.g., terminal resize).
Sourcefn render(&self, buffer: &mut Buffer)
fn render(&self, buffer: &mut Buffer)
Render this widget to the given buffer.
The widget should only write to cells within its bounds.
Sourcefn handle_input(&mut self, event: &InputEvent) -> bool
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.
Sourcefn needs_redraw(&self) -> bool
fn needs_redraw(&self) -> bool
Check if this widget needs to be redrawn.
Sourcefn clear_redraw(&mut self)
fn clear_redraw(&mut self)
Clear the redraw flag after rendering.