use async_trait::async_trait; use crate::{AsyncWidget, Frame, Size, Widget}; pub struct Layer { bottom: I1, top: I2, } impl Layer { pub fn new(bottom: I1, top: I2) -> Self { Self { bottom, top } } fn size(bottom: Size, top: Size) -> Size { Size::new(bottom.width.max(top.width), bottom.height.max(top.height)) } } impl Widget for Layer where I1: Widget, I2: Widget, { fn size( &self, frame: &mut Frame, max_width: Option, max_height: Option, ) -> Result { let bottom = self.bottom.size(frame, max_width, max_height)?; let top = self.top.size(frame, max_width, max_height)?; Ok(Self::size(bottom, top)) } fn draw(self, frame: &mut Frame) -> Result<(), E> { self.bottom.draw(frame)?; self.top.draw(frame)?; Ok(()) } } #[async_trait] impl AsyncWidget for Layer where I1: AsyncWidget + Send + Sync, I2: AsyncWidget + Send + Sync, { async fn size( &self, frame: &mut Frame, max_width: Option, max_height: Option, ) -> Result { let bottom = self.bottom.size(frame, max_width, max_height).await?; let top = self.top.size(frame, max_width, max_height).await?; Ok(Self::size(bottom, top)) } async fn draw(self, frame: &mut Frame) -> Result<(), E> { self.bottom.draw(frame).await?; self.top.draw(frame).await?; Ok(()) } }