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§
Sourcefn handle_key(
&mut self,
key: KeyEvent,
ctx: &WidgetKeyContext<'_>,
) -> WidgetKeyResult
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.
Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Cast to Any for mutable downcasting
Provided Methods§
Sourcefn priority(&self) -> u8
fn priority(&self) -> u8
Priority for key event handling (higher = checked first)
Modal widgets should have high priority to intercept input. Default is 100.
Sourcefn required_height(&self, available: u16) -> u16
fn required_height(&self, available: u16) -> u16
Calculate required height for this widget
Returns 0 if the widget doesn’t need dedicated space.
Sourcefn blocks_input(&self) -> bool
fn blocks_input(&self) -> bool
Whether this widget blocks input to the text input when active
Sourcefn is_overlay(&self) -> bool
fn is_overlay(&self) -> bool
Whether this widget is a full-screen overlay
Overlay widgets are rendered on top of everything else.