use crate::*; /// Platform backend. pub trait Engine: Send + Sync + Sized { /// Input event type type Input: Input; /// Render target type Output: Output; /// Prepare before run fn setup (&mut self) -> Usually<()> { Ok(()) } /// True if done fn exited (&self) -> bool; /// Clean up after run fn teardown (&mut self) -> Usually<()> { Ok(()) } } /// Event source pub trait Input: Send + Sync + Sized { /// Type of input event type Event; /// Result of handling input type Handled; /// Currently handled event fn event (&self) -> &Self::Event; /// Whether component should exit fn is_done (&self) -> bool; /// Mark component as done fn done (&self); } /// Render target pub trait Output: Send + Sync + Sized { /// Unit of length type Unit: Coordinate; /// Rectangle without offset type Size: Size; /// Rectangle with offset type Area: Area; /// Current output area fn area (&self) -> Self::Area; /// Mutable pointer to area fn area_mut (&mut self) -> &mut Self::Area; /// Render widget in area fn place (&mut self, area: Self::Area, content: &impl Render); #[inline] fn x (&self) -> Self::Unit { self.area().x() } #[inline] fn y (&self) -> Self::Unit { self.area().y() } #[inline] fn w (&self) -> Self::Unit { self.area().w() } #[inline] fn h (&self) -> Self::Unit { self.area().h() } #[inline] fn wh (&self) -> Self::Size { self.area().wh().into() } }