feat(cli): ✨ add more event handler methods to Component trait
This commit is contained in:
parent
cf57bb8dc0
commit
5f48801bc9
@ -81,6 +81,9 @@ pub trait Component: Downcast {
|
||||
let action = match 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::Tick) => self.handle_tick_event()?,
|
||||
Some(Event::Render) => self.handle_frame_event()?,
|
||||
Some(Event::Paste(ref event)) => self.handle_paste_event(event.clone())?,
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@ -126,6 +129,48 @@ pub trait Component: Downcast {
|
||||
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
|
||||
/// 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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user