mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
76 lines
2.9 KiB
Rust
76 lines
2.9 KiB
Rust
#![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 content; pub use self::content::*;
|
|
mod render; pub use self::render::*;
|
|
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(crate) type Usually<T> = Result<T, Box<dyn Error>>;
|
|
|
|
/// Standard optional result type.
|
|
pub(crate) type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
|
|
|
|
#[cfg(test)] #[test] fn test_layout () -> Usually<()> {
|
|
use ::tek_tui::Tui;
|
|
let area: [u16;4] = [10, 10, 20, 20];
|
|
|
|
let unit = ();
|
|
|
|
assert_eq!(Content::<TuiOut>::layout(&unit, area), [20, 20, 0, 0]);
|
|
|
|
assert_eq!(Fill::<TuiOut>::x(unit).layout(area), [10, 20, 20, 0]);
|
|
assert_eq!(Fill::<TuiOut>::y(unit).layout(area), [20, 10, 0, 20]);
|
|
assert_eq!(Fill::<TuiOut>::xy(unit).layout(area), area);
|
|
|
|
assert_eq!(Fixed::<TuiOut, u16>::x(4, unit).layout(area), [18, 20, 4, 0]);
|
|
assert_eq!(Fixed::<TuiOut, u16>::y(4, unit).layout(area), [20, 18, 0, 4]);
|
|
assert_eq!(Fixed::<TuiOut, u16>::xy(4, 4, unit).layout(area), [18, 18, 4, 4]);
|
|
|
|
let four = ||Fixed::<TuiOut>::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::<TuiOut>::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(())
|
|
}
|