diff --git a/src/ui/widgets.rs b/src/ui/widgets.rs index dd9ec22..3a2d948 100644 --- a/src/ui/widgets.rs +++ b/src/ui/widgets.rs @@ -1,3 +1,4 @@ +pub mod background; pub mod list; pub mod text; diff --git a/src/ui/widgets/background.rs b/src/ui/widgets/background.rs new file mode 100644 index 0000000..5f59b53 --- /dev/null +++ b/src/ui/widgets/background.rs @@ -0,0 +1,36 @@ +use async_trait::async_trait; +use crossterm::style::ContentStyle; +use toss::frame::{Frame, Pos, Size}; + +use super::Widget; + +pub struct Background { + inner: Box, + style: ContentStyle, +} + +impl Background { + pub fn new(inner: W, style: ContentStyle) -> Self { + Self { + inner: Box::new(inner), + style, + } + } +} + +#[async_trait] +impl Widget for Background { + fn size(&self, frame: &mut Frame, max_width: Option, max_height: Option) -> Size { + self.inner.size(frame, max_width, max_height) + } + + async fn render(self: Box, frame: &mut Frame, pos: Pos, size: Size) { + for dy in 0..size.height { + for dx in 0..size.width { + frame.write(pos + Pos::new(dx.into(), dy.into()), (" ", self.style)); + } + } + + self.inner.render(frame, pos, size).await; + } +}