Add Widget and AsyncWidget traits
This commit is contained in:
parent
4ffaae067e
commit
904f5c16fa
3 changed files with 31 additions and 0 deletions
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