Add Widget and AsyncWidget traits

This commit is contained in:
Joscha 2023-02-16 09:27:18 +01:00
parent 4ffaae067e
commit 904f5c16fa
3 changed files with 31 additions and 0 deletions

View file

@ -13,6 +13,7 @@ mod buffer;
mod frame;
mod styled;
mod terminal;
mod widget;
mod widthdb;
mod wrap;
@ -20,4 +21,5 @@ pub use buffer::{Pos, Size};
pub use frame::*;
pub use styled::*;
pub use terminal::*;
pub use widget::*;
pub use widthdb::*;

28
src/widget.rs Normal file
View file

@ -0,0 +1,28 @@
use async_trait::async_trait;
use crate::{Frame, Size};
// TODO Feature-gate these traits
pub trait Widget<E> {
fn size(
&self,
frame: &mut Frame,
max_width: Option<u16>,
max_height: Option<u16>,
) -> Result<Size, E>;
fn draw(self, frame: &mut Frame) -> Result<(), E>;
}
#[async_trait]
pub trait AsyncWidget<E> {
async fn size(
&self,
frame: &mut Frame,
max_width: Option<u16>,
max_height: Option<u16>,
) -> Result<Size, E>;
async fn draw(self, frame: &mut Frame) -> Result<(), E>;
}