use async_trait::async_trait; use crate::{AsyncWidget, Frame, Pos, Size, Widget, WidthDb}; #[derive(Debug, Clone, Copy)] pub struct Cursor { pub inner: I, pub position: Pos, } impl Cursor { pub fn new(inner: I) -> Self { Self { inner, position: Pos::ZERO, } } pub fn with_position(mut self, position: Pos) -> Self { self.position = position; self } pub fn with_position_xy(self, x: i32, y: i32) -> Self { self.with_position(Pos::new(x, y)) } } impl Widget for Cursor where I: Widget, { fn size( &self, widthdb: &mut WidthDb, max_width: Option, max_height: Option, ) -> Result { self.inner.size(widthdb, max_width, max_height) } fn draw(self, frame: &mut Frame) -> Result<(), E> { self.inner.draw(frame)?; frame.show_cursor(self.position); Ok(()) } } #[async_trait] impl AsyncWidget for Cursor where I: AsyncWidget + Send + Sync, { async fn size( &self, widthdb: &mut WidthDb, max_width: Option, max_height: Option, ) -> Result { self.inner.size(widthdb, max_width, max_height).await } async fn draw(self, frame: &mut Frame) -> Result<(), E> { self.inner.draw(frame).await?; frame.show_cursor(self.position); Ok(()) } }