//! What a drawing can be taken out of, and what it cannot. use iris::core::{UiRegion, UiScalar, UiSpan}; /// A box `size` tall whose top is `rel` of the way down the window. fn fixed(rel: f32, size: f32) -> UiRegion { UiRegion::new( UiSpan::FULL, UiSpan::new(UiScalar { rel, abs: 0.0 }, UiScalar { rel, abs: size }), ) } #[test] fn a_fixed_length_cannot_be_stretched_out_of() { assert!(!fixed(0.0, 164.0).stretchable()); assert!(!fixed(0.5, 164.0).stretchable()); assert!(UiRegion::FULL.stretchable()); } #[test] fn a_stretch_keeps_each_part_at_its_fraction() { let to = fixed(0.0, 98.0); // A part filling the window fills what replaced it. assert_eq!(UiRegion::FULL.stretch(&UiRegion::FULL, &to), to); // And the middle half of it stays the middle half. let half = UiRegion::new( UiSpan::FULL, UiSpan::new(UiScalar::rel(0.25), UiScalar::rel(0.75)), ); assert_eq!( half.stretch(&UiRegion::FULL, &to), UiRegion::new( UiSpan::FULL, UiSpan::new( UiScalar { rel: 0.0, abs: 24.5 }, UiScalar { rel: 0.0, abs: 73.5 } ) ) ); }