From 32f1ad5aae45820abab0da7d2967a57f56df7cc3 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 20 Jul 2022 21:04:06 +0200 Subject: [PATCH] Add basic HRule and VRule widgets --- src/ui/widgets.rs | 1 + src/ui/widgets/rules.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/ui/widgets/rules.rs diff --git a/src/ui/widgets.rs b/src/ui/widgets.rs index 7151aac..3e41eb2 100644 --- a/src/ui/widgets.rs +++ b/src/ui/widgets.rs @@ -1,6 +1,7 @@ pub mod background; pub mod empty; pub mod list; +pub mod rules; pub mod text; use async_trait::async_trait; diff --git a/src/ui/widgets/rules.rs b/src/ui/widgets/rules.rs new file mode 100644 index 0000000..9fcc5df --- /dev/null +++ b/src/ui/widgets/rules.rs @@ -0,0 +1,36 @@ +use async_trait::async_trait; +use toss::frame::{Frame, Pos, Size}; + +use super::Widget; + +pub struct HRule; + +#[async_trait] +impl Widget for HRule { + fn size(&self, _frame: &mut Frame, _max_width: Option, _max_height: Option) -> Size { + Size::new(0, 1) + } + + async fn render(self: Box, frame: &mut Frame) { + let size = frame.size(); + for x in 0..size.width as i32 { + frame.write(Pos::new(x, 0), "─"); + } + } +} + +pub struct VRule; + +#[async_trait] +impl Widget for VRule { + fn size(&self, _frame: &mut Frame, _max_width: Option, _max_height: Option) -> Size { + Size::new(1, 0) + } + + async fn render(self: Box, frame: &mut Frame) { + let size = frame.size(); + for y in 0..size.height as i32 { + frame.write(Pos::new(0, y), "│"); + } + } +}