component: impl Component for Box<dyn Component>

Useful to have.
pull/227/head
Manos Pitsidianakis 2023-06-13 19:11:59 +03:00
parent 155fb41b93
commit 5c9b3fb044
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
2 changed files with 46 additions and 2 deletions

View File

@ -164,3 +164,45 @@ pub trait Component: Display + Debug + Send + Sync {
String::new()
}
}
impl Component for Box<dyn Component> {
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
(**self).draw(grid, area, context)
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
(**self).process_event(event, context)
}
fn is_dirty(&self) -> bool {
(**self).is_dirty()
}
fn is_visible(&self) -> bool {
(**self).is_visible()
}
fn can_quit_cleanly(&mut self, context: &Context) -> bool {
(**self).can_quit_cleanly(context)
}
fn set_dirty(&mut self, value: bool) {
(**self).set_dirty(value)
}
fn kill(&mut self, id: ComponentId, context: &mut Context) {
(**self).kill(id, context)
}
fn id(&self) -> ComponentId {
(**self).id()
}
fn shortcuts(&self, context: &Context) -> ShortcutMaps {
(**self).shortcuts(context)
}
fn status(&self, context: &Context) -> String {
(**self).status(context)
}
}

View File

@ -21,8 +21,9 @@
//! The application's state.
//!
//! The UI crate has an `Box<dyn Component>`-Component-System design. The system
//! part, is also the application's state, so they're both merged in the
//! The UI crate has an [`Box<dyn
//! Component>`](crate::components::Component)-Component-System design. The
//! system part, is also the application's state, so they're both merged in the
//! [`State`] struct.
//!
//! [`State`] owns all the Components of the UI. In the application's main event
@ -1246,6 +1247,7 @@ impl State {
}
Some(false)
}
/// Switch back to the terminal's main screen (The command line the user
/// sees before opening the application)
pub fn switch_to_main_screen(&mut self) {