⎇ 76722686b0999e997dbe9c280ff9ea8567e0e95c
tests/generated/grid_percent_items_nested_with_margin.rs
History
Who touched what
raw
Grid: Fix sizing issues in complex cases (#355)
1#[test]
2fn grid_percent_items_nested_with_margin() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node00 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
10 margin: taffy::geometry::Rect {
11 left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12 right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13 top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14 bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
15 },
16 ..Default::default()
17 })
18 .unwrap();
19 let node0 = taffy
20 .new_with_children(
21 taffy::style::Style {
22 display: taffy::style::Display::Grid,
23 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
24 ..Default::default()
25 },
26 &[node00],
27 )
28 .unwrap();
29 let node = taffy
30 .new_with_children(
31 taffy::style::Style {
32 display: taffy::style::Display::Grid,
33 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
34 ..Default::default()
35 },
36 &[node0],
37 )
38 .unwrap();
39 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
40 println!("\nComputed tree:");
41 taffy::debug::print_tree(&taffy, node);
42 println!();
43 let Layout { size, location, .. } = taffy.layout(node).unwrap();
44 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
45 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 10f32, size.height);
46 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
47 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
48 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
49 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
50 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.height);
51 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
52 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
53 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
54 assert_eq!(size.width, 45f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 45f32, size.width);
55 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, size.height);
56 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 5f32, location.x);
57 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 5f32, location.y);
58}