Measure container children without intermediate placement
This commit is contained in:
1 parent
c330ecec2b
commit
7601aa2a5d
6 files changed
+81
-38
No files matched your search
@@ -914,3 +914,40 @@ fn resizing_a_fixed_frame_recomposes_its_contents_without_drawing_them() {
|
||||
assert_eq!(mask(&warm, leaf.id()), mask(&cold, other.id()));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_span_does_not_place_its_measurement_before_assigning_the_childs_slot() {
|
||||
struct MeasuredBox(Rc<Cell<usize>>);
|
||||
|
||||
impl Widget for MeasuredBox {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
self.0.set(self.0.get() + 1);
|
||||
painter.px_size();
|
||||
painter.primitive(RectPrimitive::color(Color::BLUE));
|
||||
Size::from((100, 50))
|
||||
}
|
||||
}
|
||||
|
||||
let mut h = Harness::new((400, 200));
|
||||
let draws = Rc::new(Cell::new(0));
|
||||
let leaf = MeasuredBox(draws.clone()).add(&mut h.rsc);
|
||||
h.set_root((leaf,).span(Dir::RIGHT).width(rel(1.0)).height(rel(1.0)));
|
||||
|
||||
assert_eq!(draws.get(), 3);
|
||||
assert_corners!(h, leaf, (0, 75), (100, 125));
|
||||
assert_eq!(
|
||||
primitive_bounds(&h, leaf.id()),
|
||||
vec![h.region(&leaf.id()).unwrap()]
|
||||
);
|
||||
h.frame();
|
||||
assert_eq!(draws.get(), 3);
|
||||
|
||||
h.resize((600, 300));
|
||||
h.frame();
|
||||
assert_eq!(draws.get(), 6);
|
||||
assert_corners!(h, leaf, (0, 125), (100, 175));
|
||||
assert_eq!(
|
||||
primitive_bounds(&h, leaf.id()),
|
||||
vec![h.region(&leaf.id()).unwrap()]
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user