//! Where a frame puts things, with no window to put them in. use iris::harness::{Harness, assert_corners}; use iris::prelude::*; /// A fixed 100 wide, and the rest of the 400 to its neighbour. fn two_rects(h: &mut Harness) -> (WidgetId, WidgetId) { let left = rect(Color::RED).width(100).add(&mut h.rsc); let right = rect(Color::BLUE).add(&mut h.rsc); h.set_root((left, right).span(Dir::RIGHT)); (left.id(), right.id()) } #[test] fn a_span_gives_each_child_the_width_it_asked_for() { let mut h = Harness::new((400, 200)); let (left, right) = two_rects(&mut h); assert_corners!(h, left, (0, 0), (100, 200)); assert_corners!(h, right, (100, 0), (400, 200)); } #[test] fn resizing_relays_out_against_the_new_output() { let mut h = Harness::new((400, 200)); let (left, right) = two_rects(&mut h); h.resize((800, 100)); assert!(h.needs_redraw()); h.frame(); assert_corners!(h, left, (0, 0), (100, 100)); assert_corners!(h, right, (100, 0), (800, 100)); } #[test] fn an_empty_widget_takes_a_share_of_a_span() { let mut h = Harness::new((400, 200)); let gap = ().add(&mut h.rsc); let right = rect(Color::BLUE).width(100).add(&mut h.rsc); h.set_root((gap, right).span(Dir::RIGHT)); assert_corners!(h, gap, (0, 0), (300, 200)); assert_corners!(h, right, (300, 0), (400, 200)); } #[test] fn a_child_drawn_twice_moves_once() { let mut h = Harness::new((400, 200)); // `Aligned` draws its child twice; listing it twice would move it twice. let inner = rect(Color::BLUE).add(&mut h.rsc); let centered = inner.center().width(200).add(&mut h.rsc); let left = rect(Color::RED).width(100).add(&mut h.rsc); h.set_root((left, centered).span(Dir::RIGHT)); assert_corners!(h, inner, (100, 0), (300, 200)); h.rsc[left].x = Some(Len::abs(150)); h.frame(); assert_corners!(h, inner, (150, 0), (350, 200)); }