Skip to main content

Component

Trait Component 

Source
pub trait Component: Send + Sync {
    // Required methods
    fn render(&self, width: usize) -> Vec<String>;
    fn invalidate(&self);
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn handle_input(&self, _data: &str) -> bool { ... }
    fn wants_key_release(&self) -> bool { ... }
}
Expand description

Component interface - all components must implement this.

Components are the building blocks of the TUI. Each component can render itself to a list of strings (one per line) for a given viewport width.

Required Methods§

Source

fn render(&self, width: usize) -> Vec<String>

Render the component to lines for the given viewport width.

§Arguments
  • width - Current viewport width in columns
§Returns

Array of strings, each representing a line

Source

fn invalidate(&self)

Invalidate any cached rendering state. Called when theme changes or when component needs to re-render from scratch.

Source

fn as_any(&self) -> &dyn Any

Downcast to Any for runtime type checking. This enables the layout system to check for LayoutNodeProvider.

Provided Methods§

Source

fn handle_input(&self, _data: &str) -> bool

Optional handler for keyboard input when component has focus.

§Arguments
  • data - Raw input data (key sequence)
§Returns

true if the input was consumed, false otherwise

Source

fn wants_key_release(&self) -> bool

If true, component receives key release events (Kitty protocol). Default is false - release events are filtered out.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§