//#![feature(lazy_type_alias)] #![feature(type_alias_impl_trait)] #![feature(impl_trait_in_assoc_type)] mod coordinate; pub use self::coordinate::*; mod size; pub use self::size::*; mod area; pub use self::area::*; mod output; pub use self::output::*; mod thunk; pub use self::thunk::*; mod when; pub use self::when::*; mod either; pub use self::either::*; mod map; pub use self::map::*; mod reduce; pub use self::reduce::*; mod align; pub use self::align::*; mod direction; pub use self::direction::*; mod measure; pub use self::measure::*; mod transform_xy; pub use self::transform_xy::*; mod transform_xy_unit; pub use self::transform_xy_unit::*; mod edn_view; pub use self::edn_view::*; pub(crate) use ::tek_edn::*; pub(crate) use std::marker::PhantomData; pub(crate) use std::error::Error; /// Standard result type. pub type Usually = Result>; /// Standard optional result type. pub type Perhaps = Result, Box>; #[cfg(test)] #[test] fn test_stub_output () -> Usually<()> { use crate::*; struct TestOutput([u16;4]); impl Output for TestOutput { type Unit = u16; type Size = [u16;2]; type Area = [u16;4]; fn area (&self) -> [u16;4] { self.0 } fn area_mut (&mut self) -> &mut [u16;4] { &mut self.0 } fn place (&mut self, _: [u16;4], _: &impl Render) { () } } impl Content for String { fn render (&self, to: &mut TestOutput) { to.area_mut().set_w(self.len() as u16); } } Ok(()) } #[cfg(test)] #[test] fn test_dimensions () { use crate::*; assert_eq!(Area::center(&[10u16, 10, 20, 20]), [20, 20]); } #[cfg(test)] #[test] fn test_layout () -> Usually<()> { use ::tek_tui::{*, tek_output::*}; let area: [u16;4] = [10, 10, 20, 20]; let unit = (); assert_eq!(Content::::layout(&unit, area), [20, 20, 0, 0]); assert_eq!(Content::::layout(&Fill::<()>::x(unit), area), [10, 20, 20, 0]); assert_eq!(Render::::layout(&Fill::<()>::x(unit), area), [10, 20, 20, 0]); assert_eq!(Fill::<()>::y(unit).layout(area), [20, 10, 0, 20]); assert_eq!(Fill::<()>::xy(unit).layout(area), area); assert_eq!(Fixed::::x(4, unit).layout(area), [18, 20, 4, 0]); assert_eq!(Fixed::::y(4, unit).layout(area), [20, 18, 0, 4]); assert_eq!(Fixed::::xy(4, 4, unit).layout(area), [18, 18, 4, 4]); let four = ||Fixed::::xy(4, 4, unit); assert_eq!(Align::nw(four()).layout(area), [10, 10, 4, 4]); assert_eq!(Align::n(four()).layout(area), [18, 10, 4, 4]); assert_eq!(Align::ne(four()).layout(area), [26, 10, 4, 4]); assert_eq!(Align::e(four()).layout(area), [26, 18, 4, 4]); assert_eq!(Align::se(four()).layout(area), [26, 26, 4, 4]); assert_eq!(Align::s(four()).layout(area), [18, 26, 4, 4]); assert_eq!(Align::sw(four()).layout(area), [10, 26, 4, 4]); assert_eq!(Align::w(four()).layout(area), [10, 18, 4, 4]); let two_by_four = ||Fixed::::xy(4, 2, unit); assert_eq!(Align::nw(two_by_four()).layout(area), [10, 10, 4, 2]); assert_eq!(Align::n(two_by_four()).layout(area), [18, 10, 4, 2]); assert_eq!(Align::ne(two_by_four()).layout(area), [26, 10, 4, 2]); assert_eq!(Align::e(two_by_four()).layout(area), [26, 19, 4, 2]); assert_eq!(Align::se(two_by_four()).layout(area), [26, 28, 4, 2]); assert_eq!(Align::s(two_by_four()).layout(area), [18, 28, 4, 2]); assert_eq!(Align::sw(two_by_four()).layout(area), [10, 28, 4, 2]); assert_eq!(Align::w(two_by_four()).layout(area), [10, 19, 4, 2]); Ok(()) }