⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/grid/grid_percent_items_nested_moderate.rs
Historia
Quién tocó qué
crudo
CSS Grid: named lines and areas (#840)
1#[test]
2#[allow(non_snake_case)]
3fn grid_percent_items_nested_moderate__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 taffy.disable_rounding();
8 let node00 = taffy
9 .new_leaf(taffy::style::Style {
10 size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.45f32), height: auto() },
11 margin: taffy::geometry::Rect {
12 left: percent(0.05f32),
13 right: percent(0.05f32),
14 top: percent(0.05f32),
15 bottom: percent(0.05f32),
16 },
17 padding: taffy::geometry::Rect {
18 left: length(3f32),
19 right: length(3f32),
20 top: length(3f32),
21 bottom: length(3f32),
22 },
23 ..Default::default()
24 })
25 .unwrap();
26 let node0 = taffy
27 .new_with_children(
28 taffy::style::Style {
29 display: taffy::style::Display::Grid,
30 size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.5f32), height: auto() },
31 margin: taffy::geometry::Rect {
32 left: length(5f32),
33 right: length(5f32),
34 top: length(5f32),
35 bottom: length(5f32),
36 },
37 padding: taffy::geometry::Rect {
38 left: percent(0.03f32),
39 right: percent(0.03f32),
40 top: percent(0.03f32),
41 bottom: percent(0.03f32),
42 },
43 ..Default::default()
44 },
45 &[node00],
46 )
47 .unwrap();
48 let node = taffy
49 .new_with_children(
50 taffy::style::Style {
51 display: taffy::style::Display::Grid,
52 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(200f32), height: auto() },
53 padding: taffy::geometry::Rect {
54 left: length(3f32),
55 right: length(3f32),
56 top: length(3f32),
57 bottom: length(3f32),
58 },
59 ..Default::default()
60 },
61 &[node0],
62 )
63 .unwrap();
64 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
65 println!("\nComputed tree:");
66 taffy.print_tree(node);
67 println!();
68 let layout = taffy.layout(node).unwrap();
69 let Layout { size, location, .. } = layout;
70 assert!((size.width - 200f32).abs() < 0.1, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
71 assert!(
72 (size.height - 42.15625f32).abs() < 0.1,
73 "height of node {:?}. Expected {}. Actual {}",
74 node,
75 42.15625f32,
76 size.height
77 );
78 assert!((location.x - 0f32).abs() < 0.1, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
79 assert!((location.y - 0f32).abs() < 0.1, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
80 let layout = taffy.layout(node0).unwrap();
81 let Layout { size, location, .. } = layout;
82 assert!((size.width - 97f32).abs() < 0.1, "width of node {:?}. Expected {}. Actual {}", node0, 97f32, size.width);
83 assert!(
84 (size.height - 26.15625f32).abs() < 0.1,
85 "height of node {:?}. Expected {}. Actual {}",
86 node0,
87 26.15625f32,
88 size.height
89 );
90 assert!((location.x - 8f32).abs() < 0.1, "x of node {:?}. Expected {}. Actual {}", node0, 8f32, location.x);
91 assert!((location.y - 8f32).abs() < 0.1, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
92 let layout = taffy.layout(node00).unwrap();
93 let Layout { size, location, .. } = layout;
94 assert!(
95 (size.width - 38.40625f32).abs() < 0.1,
96 "width of node {:?}. Expected {}. Actual {}",
97 node00,
98 38.40625f32,
99 size.width
100 );
101 assert!((size.height - 6f32).abs() < 0.1, "height of node {:?}. Expected {}. Actual {}", node00, 6f32, size.height);
102 assert!(
103 (location.x - 10.078125f32).abs() < 0.1,
104 "x of node {:?}. Expected {}. Actual {}",
105 node00,
106 10.078125f32,
107 location.x
108 );
109 assert!(
110 (location.y - 10.078125f32).abs() < 0.1,
111 "y of node {:?}. Expected {}. Actual {}",
112 node00,
113 10.078125f32,
114 location.y
115 );
116}
117
118#[test]
119#[allow(non_snake_case)]
120fn grid_percent_items_nested_moderate__content_box() {
121 #[allow(unused_imports)]
122 use taffy::{prelude::*, Layout};
123 let mut taffy = crate::new_test_tree();
124 taffy.disable_rounding();
125 let node00 = taffy
126 .new_leaf(taffy::style::Style {
127 box_sizing: taffy::style::BoxSizing::ContentBox,
128 size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.45f32), height: auto() },
129 margin: taffy::geometry::Rect {
130 left: percent(0.05f32),
131 right: percent(0.05f32),
132 top: percent(0.05f32),
133 bottom: percent(0.05f32),
134 },
135 padding: taffy::geometry::Rect {
136 left: length(3f32),
137 right: length(3f32),
138 top: length(3f32),
139 bottom: length(3f32),
140 },
141 ..Default::default()
142 })
143 .unwrap();
144 let node0 = taffy
145 .new_with_children(
146 taffy::style::Style {
147 display: taffy::style::Display::Grid,
148 box_sizing: taffy::style::BoxSizing::ContentBox,
149 size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.5f32), height: auto() },
150 margin: taffy::geometry::Rect {
151 left: length(5f32),
152 right: length(5f32),
153 top: length(5f32),
154 bottom: length(5f32),
155 },
156 padding: taffy::geometry::Rect {
157 left: percent(0.03f32),
158 right: percent(0.03f32),
159 top: percent(0.03f32),
160 bottom: percent(0.03f32),
161 },
162 ..Default::default()
163 },
164 &[node00],
165 )
166 .unwrap();
167 let node = taffy
168 .new_with_children(
169 taffy::style::Style {
170 display: taffy::style::Display::Grid,
171 box_sizing: taffy::style::BoxSizing::ContentBox,
172 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(200f32), height: auto() },
173 padding: taffy::geometry::Rect {
174 left: length(3f32),
175 right: length(3f32),
176 top: length(3f32),
177 bottom: length(3f32),
178 },
179 ..Default::default()
180 },
181 &[node0],
182 )
183 .unwrap();
184 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
185 println!("\nComputed tree:");
186 taffy.print_tree(node);
187 println!();
188 let layout = taffy.layout(node).unwrap();
189 let Layout { size, location, .. } = layout;
190 assert!((size.width - 206f32).abs() < 0.1, "width of node {:?}. Expected {}. Actual {}", node, 206f32, size.width);
191 assert!((size.height - 44f32).abs() < 0.1, "height of node {:?}. Expected {}. Actual {}", node, 44f32, size.height);
192 assert!((location.x - 0f32).abs() < 0.1, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
193 assert!((location.y - 0f32).abs() < 0.1, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
194 let layout = taffy.layout(node0).unwrap();
195 let Layout { size, location, .. } = layout;
196 assert!((size.width - 112f32).abs() < 0.1, "width of node {:?}. Expected {}. Actual {}", node0, 112f32, size.width);
197 assert!(
198 (size.height - 28f32).abs() < 0.1,
199 "height of node {:?}. Expected {}. Actual {}",
200 node0,
201 28f32,
202 size.height
203 );
204 assert!((location.x - 8f32).abs() < 0.1, "x of node {:?}. Expected {}. Actual {}", node0, 8f32, location.x);
205 assert!((location.y - 8f32).abs() < 0.1, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
206 let layout = taffy.layout(node00).unwrap();
207 let Layout { size, location, .. } = layout;
208 assert!((size.width - 51f32).abs() < 0.1, "width of node {:?}. Expected {}. Actual {}", node00, 51f32, size.width);
209 assert!((size.height - 6f32).abs() < 0.1, "height of node {:?}. Expected {}. Actual {}", node00, 6f32, size.height);
210 assert!((location.x - 11f32).abs() < 0.1, "x of node {:?}. Expected {}. Actual {}", node00, 11f32, location.x);
211 assert!((location.y - 11f32).abs() < 0.1, "y of node {:?}. Expected {}. Actual {}", node00, 11f32, location.y);
212}