diff --git a/Cargo.toml b/Cargo.toml index ca266b3..f7797f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ cc = "1.0" [dependencies] crossterm = "0.28.1" -downcast-rs = "2.0.1" [profile.dev] opt-level = 1 diff --git a/src/lib.rs b/src/lib.rs index f5ee407..ba4f301 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,17 +1,21 @@ +use std::{ + any::{Any, TypeId}, + collections::HashMap, +}; + pub mod text; -pub mod macros; -use std::fmt::Debug; +pub trait Event: Any {} -use downcast_rs::{impl_downcast, DowncastSync}; -pub trait Component: DowncastSync + Debug {} -impl_downcast!(sync Component); +pub struct Screen { + element: Box, + event_handlers: HashMap)>>, +} + +impl Screen { + +} pub trait Element { - fn get_component(&mut self) -> Option<&mut T>; - fn add_component(&mut self, component: T); -} - -pub trait Extension { - fn tick(&mut self); + fn init(&mut self, screen: &mut Screen); } diff --git a/src/macros.rs b/src/macros.rs deleted file mode 100644 index 1583097..0000000 --- a/src/macros.rs +++ /dev/null @@ -1,12 +0,0 @@ -#[macro_export] -macro_rules! components { - ($($a:ty: $e:expr),*) => { - { - let mut hm: HashMap> = HashMap::new(); - $( - hm.insert(TypeId::of::<$a>(), Box::new($e)); - )* - hm - } - }; -} diff --git a/src/main.rs b/src/main.rs index 9f00e6c..58dfaaa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,3 @@ -use osui::{ - text::{text, DisplayComponent}, - Element, -}; - fn main() { - let mut e = text("Hello, World!"); - - if let Some(comp) = e.get_component::() { - println!("Ok: {:?}", comp); - } + } diff --git a/src/text.rs b/src/text.rs index 197b2cc..e69de29 100644 --- a/src/text.rs +++ b/src/text.rs @@ -1,33 +0,0 @@ -use crate::{components, Component, Element}; -use std::{any::TypeId, collections::HashMap}; - -#[derive(Debug)] -pub struct DisplayComponent(); -impl Component for DisplayComponent {} - -pub struct Text { - text: String, - components: HashMap>, -} - -impl Element for Text { - fn get_component(&mut self) -> Option<&mut T> { - self.components - .get_mut(&TypeId::of::())? - .downcast_mut::() - } - - fn add_component(&mut self, component: T) { - if !self.components.contains_key(&TypeId::of::()) { - self.components - .insert(TypeId::of::(), Box::new(component)); - } - } -} - -pub fn text(text: &str) -> Text { - Text { - text: text.to_string(), - components: components!(DisplayComponent: DisplayComponent()), - } -}