From 47df35d9dbee7c093ba03ad37dce944340306b3e Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 16 Feb 2023 16:07:05 +0100 Subject: [PATCH] Add Empty widget --- src/widgets.rs | 2 ++ src/widgets/empty.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/widgets/empty.rs diff --git a/src/widgets.rs b/src/widgets.rs index c1021ec..7503859 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -1,9 +1,11 @@ mod border; +mod empty; mod float; mod padding; mod text; pub use border::*; +pub use empty::*; pub use float::*; pub use padding::*; pub use text::*; diff --git a/src/widgets/empty.rs b/src/widgets/empty.rs new file mode 100644 index 0000000..86881e2 --- /dev/null +++ b/src/widgets/empty.rs @@ -0,0 +1,60 @@ +use async_trait::async_trait; + +use crate::{AsyncWidget, Frame, Size, Widget}; + +#[derive(Debug, Default, Clone, Copy)] +pub struct Empty { + size: Size, +} + +impl Empty { + pub fn new() -> Self { + Self { size: Size::ZERO } + } + + pub fn width(mut self, width: u16) -> Self { + self.size.width = width; + self + } + + pub fn height(mut self, height: u16) -> Self { + self.size.height = height; + self + } + + pub fn size(mut self, size: Size) -> Self { + self.size = size; + self + } +} + +impl Widget for Empty { + fn size( + &self, + _frame: &mut Frame, + _max_width: Option, + _max_height: Option, + ) -> Result { + Ok(self.size) + } + + fn draw(self, _frame: &mut Frame) -> Result<(), E> { + Ok(()) + } +} + +#[async_trait] +impl AsyncWidget for Empty { + async fn size( + &self, + _frame: &mut Frame, + _max_width: Option, + _max_height: Option, + ) -> Result { + Ok(self.size) + } + + async fn draw(self, _frame: &mut Frame) -> Result<(), E> { + Ok(()) + } +}