diff --git a/src/elements/mod.rs b/src/elements/mod.rs index 8ea79e0..0dfc814 100644 --- a/src/elements/mod.rs +++ b/src/elements/mod.rs @@ -1,8 +1,10 @@ pub mod div; pub mod flex; +pub mod shape; pub use div::*; pub use flex::*; +pub use shape::*; use crate::Element; diff --git a/src/elements/shape.rs b/src/elements/shape.rs new file mode 100644 index 0000000..5523b9d --- /dev/null +++ b/src/elements/shape.rs @@ -0,0 +1,59 @@ +use crate::widget::Element; + +pub struct RoundedOutline; + +impl Element for RoundedOutline { + fn render(&mut self, scope: &mut crate::prelude::RenderScope) { + let (w, h) = scope.get_size_or_parent(); + if w > 2 && h > 2 { + let d = "─".repeat(w as usize - 2); + scope.draw_text(&format!( + "╭{d}╮{}\n╰{d}╯", + format!("\n│{}│", " ".repeat(w as usize - 2)).repeat(h as usize - 2), + )); + } + } + + fn as_any(&self) -> &dyn std::any::Any { + self + } + + fn as_any_mut(&mut self) -> &mut dyn std::any::Any { + self + } +} + +impl RoundedOutline { + pub fn new() -> Self { + Self + } +} + +pub struct Outline; + +impl Element for Outline { + fn render(&mut self, scope: &mut crate::prelude::RenderScope) { + let (w, h) = scope.get_size_or_parent(); + if w > 2 && h > 2 { + let d = "─".repeat(w as usize - 2); + scope.draw_text(&format!( + "┌{d}┐{}\n└{d}┘", + format!("\n│{}│", " ".repeat(w as usize - 2)).repeat(h as usize - 2), + )); + } + } + + fn as_any(&self) -> &dyn std::any::Any { + self + } + + fn as_any_mut(&mut self) -> &mut dyn std::any::Any { + self + } +} + +impl Outline { + pub fn new() -> Self { + Self + } +} diff --git a/src/main.rs b/src/main.rs index feeac18..575b7fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,33 +10,19 @@ fn main() -> std::io::Result<()> { fn app() -> Rsx { rsx! { - @Transform::center(); - FlexCol { - test => (1) - test => (3) - } (0x0000ff, 4) - } -} - -fn test(inc: i32) -> Rsx { - let count = use_state(0); - - std::thread::spawn({ - let count = count.clone(); - move || loop { - std::thread::sleep(std::time::Duration::from_millis(50)); - **count.get() += inc; - } - }); - - rsx! { - @Transform::new().dimensions(40, 3); + @transform! { + width: Full, + height: Full, + }; Div { - @transform! { x: Center, y: Center, width: 5 }; - Div { - %count - "{count}" - } (0x00ff00) - } (0xff0000) + @transform! { + width: Full, + height: Full, + }; + RoundedOutline {} + + @Transform::center(); + "Welcome To OSUI!" + } (0x000000) } }