diff --git a/src/widget.rs b/src/widget.rs index 65f95f8..9062411 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -1,8 +1,8 @@ use async_trait::async_trait; use crate::widgets::{ - Background, Border, Boxed, BoxedAsync, Either2, Either3, Float, JoinSegment, Layer2, Padding, - Resize, + Background, Border, Boxed, BoxedAsync, Desync, Either2, Either3, Float, JoinSegment, Layer2, + Padding, Resize, }; use crate::{Frame, Size, WidthDb}; @@ -53,6 +53,9 @@ pub trait WidgetExt: Sized { { BoxedAsync::new(self) } + fn desync(self) -> Desync { + Desync(self) + } fn first2(self) -> Either2 { Either2::First(self) diff --git a/src/widgets.rs b/src/widgets.rs index 4991618..7c3fc55 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -2,6 +2,7 @@ pub mod background; pub mod border; pub mod boxed; pub mod cursor; +pub mod desync; pub mod editor; pub mod either; pub mod empty; @@ -17,6 +18,7 @@ pub use background::*; pub use border::*; pub use boxed::*; pub use cursor::*; +pub use desync::*; pub use editor::*; pub use either::*; pub use empty::*; diff --git a/src/widgets/desync.rs b/src/widgets/desync.rs new file mode 100644 index 0000000..67e7488 --- /dev/null +++ b/src/widgets/desync.rs @@ -0,0 +1,42 @@ +use async_trait::async_trait; + +use crate::{AsyncWidget, Widget}; + +pub struct Desync(pub I); + +impl Widget for Desync +where + I: Widget, +{ + fn size( + &self, + widthdb: &mut crate::WidthDb, + max_width: Option, + max_height: Option, + ) -> Result { + self.0.size(widthdb, max_width, max_height) + } + + fn draw(self, frame: &mut crate::Frame) -> Result<(), E> { + self.0.draw(frame) + } +} + +#[async_trait] +impl AsyncWidget for Desync +where + I: Widget + Send + Sync, +{ + async fn size( + &self, + widthdb: &mut crate::WidthDb, + max_width: Option, + max_height: Option, + ) -> Result { + self.0.size(widthdb, max_width, max_height) + } + + async fn draw(self, frame: &mut crate::Frame) -> Result<(), E> { + self.0.draw(frame) + } +}