feat(cli): add more event handler methods to Component trait

This commit is contained in:
Lucas Colombo 2024-09-17 20:14:41 -03:00
parent cf57bb8dc0
commit 5f48801bc9
Signed by: lucas
GPG Key ID: EF34786CFEFFAE35

View File

@ -81,6 +81,9 @@ pub trait Component: Downcast {
let action = match event { let action = match event {
Some(Event::Key(key_event)) => self.handle_key_events(key_event)?, Some(Event::Key(key_event)) => self.handle_key_events(key_event)?,
Some(Event::Mouse(mouse_event)) => self.handle_mouse_events(mouse_event)?, Some(Event::Mouse(mouse_event)) => self.handle_mouse_events(mouse_event)?,
Some(Event::Tick) => self.handle_tick_event()?,
Some(Event::Render) => self.handle_frame_event()?,
Some(Event::Paste(ref event)) => self.handle_paste_event(event.clone())?,
_ => None, _ => None,
}; };
@ -126,6 +129,48 @@ pub trait Component: Downcast {
Ok(None) Ok(None)
} }
/// Handle Tick events and produce actions if necessary.
///
/// # Arguments
///
/// * `tick` - A tick event to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn handle_tick_event(&mut self) -> Result<Option<Action>> {
Ok(None)
}
/// Handle frame events and produce actions if necessary.
///
/// # Arguments
///
/// * `tick` - A tick event to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn handle_frame_event(&mut self) -> Result<Option<Action>> {
Ok(None)
}
/// Handle paste events and produce actions if necessary.
///
/// # Arguments
///
/// * `message` - A string message to be processed.
///
/// # Returns
///
/// * `Result<Option<Action>>` - An action to be processed or none.
#[allow(unused_variables)]
fn handle_paste_event(&mut self, message: String) -> Result<Option<Action>> {
Ok(None)
}
/// Update the state of the component based on a received action. If you want to override this /// Update the state of the component based on a received action. If you want to override this
/// method, you will lose calling the children's update methods. That's why we provide a helper /// method, you will lose calling the children's update methods. That's why we provide a helper
/// function to update the children's state. Something like the following is recommended: /// function to update the children's state. Something like the following is recommended: