⎇ 568f643327ec6b4879df0087def7f4e66b6acafb
tests/generated/grid_percent_items_nested_with_padding_margin.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Rename `Points`/`points` to `Length`/`length` in many APIs (#459)
1#[test]
2fn grid_percent_items_nested_with_padding_margin() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout};
5 let mut taffy = taffy::Taffy::new();
6 let node000 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
9 margin: taffy::geometry::Rect {
10 left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
11 right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12 top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13 bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14 },
15 padding: taffy::geometry::Rect {
16 left: taffy::style::LengthPercentage::Length(3f32),
17 right: taffy::style::LengthPercentage::Length(3f32),
18 top: taffy::style::LengthPercentage::Length(3f32),
19 bottom: taffy::style::LengthPercentage::Length(3f32),
20 },
21 ..Default::default()
22 })
23 .unwrap();
24 let node00 = taffy
25 .new_with_children(
26 taffy::style::Style {
27 display: taffy::style::Display::Grid,
28 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
29 margin: taffy::geometry::Rect {
30 left: taffy::style::LengthPercentageAuto::Length(5f32),
31 right: taffy::style::LengthPercentageAuto::Length(5f32),
32 top: taffy::style::LengthPercentageAuto::Length(5f32),
33 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
34 },
35 padding: taffy::geometry::Rect {
36 left: taffy::style::LengthPercentage::Percent(0.03f32),
37 right: taffy::style::LengthPercentage::Percent(0.03f32),
38 top: taffy::style::LengthPercentage::Percent(0.03f32),
39 bottom: taffy::style::LengthPercentage::Percent(0.03f32),
40 },
41 ..Default::default()
42 },
43 &[node000],
44 )
45 .unwrap();
46 let node0 = taffy
47 .new_with_children(
48 taffy::style::Style {
49 display: taffy::style::Display::Grid,
50 min_size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.6f32), height: auto() },
51 margin: taffy::geometry::Rect {
52 left: taffy::style::LengthPercentageAuto::Length(5f32),
53 right: taffy::style::LengthPercentageAuto::Length(5f32),
54 top: taffy::style::LengthPercentageAuto::Length(5f32),
55 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
56 },
57 padding: taffy::geometry::Rect {
58 left: taffy::style::LengthPercentage::Length(3f32),
59 right: taffy::style::LengthPercentage::Length(3f32),
60 top: taffy::style::LengthPercentage::Length(3f32),
61 bottom: taffy::style::LengthPercentage::Length(3f32),
62 },
63 ..Default::default()
64 },
65 &[node00],
66 )
67 .unwrap();
68 let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
69 let node = taffy
70 .new_with_children(
71 taffy::style::Style {
72 display: taffy::style::Display::Grid,
73 grid_template_rows: vec![fr(1f32), fr(4f32)],
74 size: taffy::geometry::Size {
75 width: taffy::style::Dimension::Length(200f32),
76 height: taffy::style::Dimension::Length(200f32),
77 },
78 ..Default::default()
79 },
80 &[node0, node1],
81 )
82 .unwrap();
83 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
84 println!("\nComputed tree:");
85 taffy::util::print_tree(&taffy, node);
86 println!();
87 let Layout { size, location, .. } = taffy.layout(node).unwrap();
88 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
89 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
90 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
91 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
92 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
93 assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node0, 190f32, size.width);
94 assert_eq!(size.height, 41f32, "height of node {:?}. Expected {}. Actual {}", node0, 41f32, size.height);
95 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
96 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
97 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
98 assert_eq!(size.width, 92f32, "width of node {:?}. Expected {}. Actual {}", node00, 92f32, size.width);
99 assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node00, 25f32, size.height);
100 assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node00, 8f32, location.x);
101 assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node00, 8f32, location.y);
102 let Layout { size, location, .. } = taffy.layout(node000).unwrap();
103 assert_eq!(size.width, 36f32, "width of node {:?}. Expected {}. Actual {}", node000, 36f32, size.width);
104 assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node000, 6f32, size.height);
105 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node000, 10f32, location.x);
106 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node000, 10f32, location.y);
107 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
108 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width);
109 assert_eq!(size.height, 149f32, "height of node {:?}. Expected {}. Actual {}", node1, 149f32, size.height);
110 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
111 assert_eq!(location.y, 51f32, "y of node {:?}. Expected {}. Actual {}", node1, 51f32, location.y);
112}