Skip to main content

Component

Trait Component 

Source
pub trait Component {
    // Required method
    fn draw(&mut self, frame: &mut Frame<'_>, area: Rect) -> Result<()>;

    // Provided methods
    fn register_action_handler(
        &mut self,
        _tx: UnboundedSender<Action>,
    ) -> Result<()> { ... }
    fn init(&mut self, _area: Rect) -> Result<()> { ... }
    fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>> { ... }
    fn handle_key_event(&mut self, _key: KeyEvent) -> Result<Option<Action>> { ... }
    fn handle_mouse_event(
        &mut self,
        _mouse: MouseEvent,
    ) -> Result<Option<Action>> { ... }
    fn update(&mut self, _action: Action) -> Result<Option<Action>> { ... }
}
Expand description

A visual and interactive element of the TUI.

Required Methods§

Source

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

Render the component on the screen. (REQUIRED)

§Arguments
  • f - A frame used for rendering.
  • area - The area in which the component should be drawn.
§Returns

Provided Methods§

Source

fn register_action_handler( &mut self, _tx: UnboundedSender<Action>, ) -> Result<()>

Register an action handler that can send actions for processing if necessary.

§Arguments
  • tx - An unbounded sender that can send actions.
§Returns
Source

fn init(&mut self, _area: Rect) -> Result<()>

Initialize the component with a specified area if necessary.

§Arguments
  • area - Rectangular area to initialize the component within.
§Returns
Source

fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>>

Handle an incoming terminal event and produce an action if necessary.

§Arguments
  • event - The event to be processed, or None if the caller has nothing for this component this tick.
§Returns
Source

fn handle_key_event(&mut self, _key: KeyEvent) -> Result<Option<Action>>

Handle key events and produce actions if necessary.

§Arguments
  • key - A key event to be processed.
§Returns
Source

fn handle_mouse_event(&mut self, _mouse: MouseEvent) -> Result<Option<Action>>

Handle mouse events and produce actions if necessary.

§Arguments
  • mouse - A mouse event to be processed.
§Returns
Source

fn update(&mut self, _action: Action) -> Result<Option<Action>>

Update the state of the component based on a received action. (REQUIRED)

§Arguments
  • action - An action that may modify the state of the component.
§Returns

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§