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 register_config_handler(&mut self, config: Config) -> Result<()> { ... }
fn init(&mut self, area: Size) -> 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>> { ... }
fn as_any_mut(&mut self) -> Option<&mut dyn Any> { ... }
}Expand description
Component is a trait that represents a visual and interactive element of the user interface.
Implementors of this trait can be registered with the main application loop and will be able to receive events, update state, and be rendered on the screen.
Required Methods§
Provided Methods§
Sourcefn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()>
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
color_eyre::Result<()>- An Ok result or an error.
Sourcefn register_config_handler(&mut self, config: Config) -> Result<()>
fn register_config_handler(&mut self, config: Config) -> Result<()>
Register a configuration handler that provides configuration settings if necessary.
§Arguments
config- Configuration settings.
§Returns
color_eyre::Result<()>- An Ok result or an error.
Sourcefn init(&mut self, area: Size) -> Result<()>
fn init(&mut self, area: Size) -> Result<()>
Initialize the component with a specified area if necessary.
§Arguments
area- Rectangular area to initialize the component within.
§Returns
color_eyre::Result<()>- An Ok result or an error.
Sourcefn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>>
fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>>
Handle incoming events and produce actions if necessary.
§Arguments
event- An optional event to be processed.
§Returns
color_eyre::Result<Option<Action>>- An action to be processed or none.
Sourcefn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>>
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
color_eyre::Result<Option<Action>>- An action to be processed or none.
Sourcefn handle_mouse_event(&mut self, mouse: MouseEvent) -> Result<Option<Action>>
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
color_eyre::Result<Option<Action>>- An action to be processed or none.
Sourcefn update(&mut self, action: Action) -> Result<Option<Action>>
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
color_eyre::Result<Option<Action>>- An action to be processed or none.
Sourcefn as_any_mut(&mut self) -> Option<&mut dyn Any>
fn as_any_mut(&mut self) -> Option<&mut dyn Any>
Downcast hook so the App can reach a concrete screen type
(e.g. to call Manifest::load(reference) from the command bar).
Default returns None so screens that don’t need it can ignore
this method.