Add Empty widget

This commit is contained in:
Joscha 2023-02-16 16:07:05 +01:00
parent 575faf9bbf
commit 47df35d9db
2 changed files with 62 additions and 0 deletions

View file

@ -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::*;

60
src/widgets/empty.rs Normal file
View file

@ -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<E> Widget<E> for Empty {
fn size(
&self,
_frame: &mut Frame,
_max_width: Option<u16>,
_max_height: Option<u16>,
) -> Result<Size, E> {
Ok(self.size)
}
fn draw(self, _frame: &mut Frame) -> Result<(), E> {
Ok(())
}
}
#[async_trait]
impl<E> AsyncWidget<E> for Empty {
async fn size(
&self,
_frame: &mut Frame,
_max_width: Option<u16>,
_max_height: Option<u16>,
) -> Result<Size, E> {
Ok(self.size)
}
async fn draw(self, _frame: &mut Frame) -> Result<(), E> {
Ok(())
}
}