use super::*; /// Implement the [Draw] trait for a particular drawable and [Screen]. /// /// ``` /// use tengri::{*, draw::*, term::*}; /// struct MyDrawable; /// impl_draw!(|self: MyDrawable, to: Tui|{ /// todo!() /// }); /// ``` #[macro_export] macro_rules! impl_draw ((| $self:ident:$Self:ty, $to:ident:$To:ty |$draw:block)=>{ impl Draw<$To> for $Self { fn draw ($self, $to: &mut $To) -> Usually> $draw } }); /// Drawable that supports dynamic dispatch. /// /// Drawables are composable, e.g. the [when] and [either] conditionals /// or the layout constraints. /// /// Drawables are consumable, i.e. the [Draw::draw] method receives an /// owned `self` and does not return it, consuming the drawable. /// /// To draw a thing multiple times, instead of explicitly constructing it /// every time, implement the [View] trait instead, which will construct /// a [Draw]able. /// /// ``` /// use tengri::{*, draw::*}; /// struct MyScreen(bool); /// impl Screen for MyScreen { type Unit = u16; } /// impl X for MyScreen { fn x (&self) -> u16 { 0 } } /// impl Y for MyScreen { fn y (&self) -> u16 { 0 } } /// struct MyWidget(bool); /// impl Draw for MyWidget { /// fn draw (self, screen: &mut MyScreen) -> Usually> { /// screen.0 |= self.0; /// } /// } /// let mut screen = MyScreen(false); /// MyWidget(false).draw(&mut screen); /// MyWidget(true).draw(&mut screen); /// MyWidget(false).draw(&mut screen); /// ``` pub trait Draw { fn draw (self, to: &mut T) -> Usually>; } impl> Draw for &D { fn draw (self, __: &mut T) -> Usually> { todo!() } } impl> Draw for Option { fn draw (self, __: &mut T) -> Usually> { todo!() } }