Created
May 1, 2024 06:18
-
-
Save cestlaviet8438/a5f1024de9658da7206c883d24280784 to your computer and use it in GitHub Desktop.
overriding trait methods with another trait - maybe horribly misguided considering oop background
This file contains hidden or 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
//! A [Screen] to display content. Integral to Terminal Arcade's workings. | |
use {...}; | |
/// The trait for handling drawing on the terminal and receiving events from the | |
/// user. | |
/// One should always start here when making a game/screen. | |
#[must_use] | |
pub trait Screen { | |
fn event(&mut self, _event: &Event) -> anyhow::Result<()> { | |
... | |
} | |
fn screen_created(&mut self) -> Option<Box<dyn Screen>> { | |
None | |
} | |
/* other methods... */ | |
/// Renders some UI to the screen. | |
/// This method is also called when a resize event is triggered. | |
fn render(&mut self, frame: &mut Frame<'_>); | |
/// do i want this to be my way to tell rust this is a popup? | |
/// obviously not, like this is very oop of me, but whatever this trait is already beyond saving | |
/// Returns whether this screen is a popup. | |
fn is_popup(&self) -> bool { | |
false | |
} | |
} | |
/// and then in another trait... | |
/// ideally i just want a rustful (rustic?) way to tell rust | |
/// the type information so then i can do stuff like not clear | |
/// the screen behind when rendering the popup, still direct | |
//// input to it because it is still a window, etc. | |
pub trait Popup: Screen { | |
/// override? | |
fn is_popup(&self) -> bool { | |
true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment