-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trying to move things in display objects to better manage rendering a…
…nd event handling
- Loading branch information
Showing
9 changed files
with
445 additions
and
158 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ edition = "2021" | |
anyhow = "1.0.77" | ||
crossterm = "0.27.0" | ||
ratatui = "0.25.0" | ||
tui-input = "0.8.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crossterm::event::KeyEvent; | ||
use ratatui::Frame; | ||
use crate::dive::app::App; | ||
|
||
pub trait Displayable { | ||
fn render(&mut self, app: &mut App, f: &mut Frame); | ||
fn event_handler(&mut self, app: &mut App, key: KeyEvent) -> anyhow::Result<()>; | ||
fn on_show(&mut self, app: &mut App); | ||
fn on_hide(&mut self, app: &mut App); | ||
} | ||
|
||
pub struct DisplayObject { | ||
pub id: String, // Unique identifier for this object | ||
pub priority: u8, // 0 is the highest, 255 is the lowest | ||
pub show: bool, // Does this object need to be rendered | ||
pub object: Box<dyn Displayable>, // Actual object with rendering and event handling | ||
} | ||
|
||
impl DisplayObject { | ||
pub fn new(id: &str, priority: u8, object: Box<dyn Displayable>) -> Self { | ||
Self { | ||
id: id.into(), | ||
priority, | ||
show: false, | ||
object, | ||
} | ||
} | ||
|
||
pub fn show(&mut self, app: &mut App) { | ||
self.show = true; | ||
self.object.on_show(app); | ||
} | ||
|
||
pub fn hide(&mut self, app: &mut App) { | ||
self.show = false; | ||
self.object.on_hide(app); | ||
} | ||
} |
Oops, something went wrong.