use ui_layout::*;
#[test]
fn block_vertical_margin_collapsing_between_siblings() {
let child1 = LayoutNode::new(Style {
size: SizeStyle {
height: Length::Px(20.0),
..Default::default()
},
spacing: Spacing {
margin_bottom: Length::Px(30.0),
..Default::default()
},
..Default::default()
});
let child2 = LayoutNode::new(Style {
size: SizeStyle {
height: Length::Px(20.0),
..Default::default()
},
spacing: Spacing {
margin_top: Length::Px(10.0),
..Default::default()
},
..Default::default()
});
let mut root = LayoutNode::with_children(
Style {
size: SizeStyle {
width: Length::Px(100.0),
height: Length::Auto,
..Default::default()
},
..Default::default()
},
vec![child1, child2],
);
LayoutEngine::layout(&mut root, 800.0, 600.0);
let c1_box = match &root.children[0].layout_boxes {
LayoutBoxes::Single(box_model) => box_model,
_ => panic!("Expected single box model"),
};
let c2_box = match &root.children[1].layout_boxes {
LayoutBoxes::Single(box_model) => box_model,
_ => panic!("Expected single box model"),
};
assert_eq!(c1_box.border_box.y, 0.0);
assert_eq!(c2_box.border_box.y, c1_box.border_box.height + 30.0);
}