Skip to main content

Component

Trait Component 

Source
pub trait Component {
    // Required methods
    fn render(&mut self, frame: &mut Frame<'_>, area: Rect) -> Result<()>;
    fn handle_event(&mut self, event: Event) -> Result<ComponentAction>;
}
Expand description

Trait for all UI components

Components are self-contained UI elements that:

  • Manage their own state
  • Handle their own events
  • Render themselves
  • Return actions for the app to handle

Required Methods§

Source

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

Render the component to the given area

Source

fn handle_event(&mut self, event: Event) -> Result<ComponentAction>

Handle an event (keyboard, mouse, etc.) Returns an action that the app should take

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§