diff options
Diffstat (limited to 'src/tuine/component.rs')
-rw-r--r-- | src/tuine/component.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/tuine/component.rs b/src/tuine/component.rs index c331b056..31a9899f 100644 --- a/src/tuine/component.rs +++ b/src/tuine/component.rs @@ -8,11 +8,17 @@ use tui::{backend::Backend, layout::Rect, Frame}; use super::{Event, Status}; -/// A [`Component`] is an element that displays information and can be interacted with. +pub type ShouldRender = bool; + +/// A is an element that displays information and can be interacted with. #[allow(unused_variables)] pub trait Component { + /// How to inform a component after some event takes place. Typically some enum. type Message: 'static; + /// Information passed to the component from its parent. + type Properties; + /// Handles an [`Event`]. Defaults to just ignoring the event. fn on_event( &mut self, bounds: Rect, event: Event, messages: &mut Vec<Self::Message>, @@ -20,8 +26,16 @@ pub trait Component { Status::Ignored } - fn update(&mut self, message: Self::Message) {} + /// How the component should handle a [`Self::Message`]. Defaults to doing nothing. + fn update(&mut self, message: Self::Message) -> ShouldRender { + false + } + + /// How the component should handle an update to its properties. Defaults to doing nothing. + fn change(&mut self, props: Self::Properties) -> ShouldRender { + false + } - /// Draws the [`Component`]. + /// Draws the component. fn draw<B: Backend>(&mut self, bounds: Rect, frame: &mut Frame<'_, B>); } |