Add Widget and AsyncWidget traits
This commit is contained in:
parent
4ffaae067e
commit
904f5c16fa
3 changed files with 31 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
async-trait = "0.1.64"
|
||||||
crossterm = "0.26.0"
|
crossterm = "0.26.0"
|
||||||
unicode-linebreak = "0.1.4"
|
unicode-linebreak = "0.1.4"
|
||||||
unicode-segmentation = "1.10.1"
|
unicode-segmentation = "1.10.1"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ mod buffer;
|
||||||
mod frame;
|
mod frame;
|
||||||
mod styled;
|
mod styled;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
mod widget;
|
||||||
mod widthdb;
|
mod widthdb;
|
||||||
mod wrap;
|
mod wrap;
|
||||||
|
|
||||||
|
|
@ -20,4 +21,5 @@ pub use buffer::{Pos, Size};
|
||||||
pub use frame::*;
|
pub use frame::*;
|
||||||
pub use styled::*;
|
pub use styled::*;
|
||||||
pub use terminal::*;
|
pub use terminal::*;
|
||||||
|
pub use widget::*;
|
||||||
pub use widthdb::*;
|
pub use widthdb::*;
|
||||||
|
|
|
||||||
28
src/widget.rs
Normal file
28
src/widget.rs
Normal 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>;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue