⎇ 0.7.x
tests/generated/grid/grid_percent_items_nested_with_padding_margin.rs
Historia
Quién tocó qué
crudo
Add `taffy_test_helpers` crate (#755)
1#[test]
2#[allow(non_snake_case)]
3fn grid_percent_items_nested_with_padding_margin__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node000 = 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 padding: taffy::geometry::Rect {
17 left: taffy::style::LengthPercentage::Length(3f32),
18 right: taffy::style::LengthPercentage::Length(3f32),
19 top: taffy::style::LengthPercentage::Length(3f32),
20 bottom: taffy::style::LengthPercentage::Length(3f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node00 = taffy
26 .new_with_children(
27 taffy::style::Style {
28 display: taffy::style::Display::Grid,
29 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
30 margin: taffy::geometry::Rect {
31 left: taffy::style::LengthPercentageAuto::Length(5f32),
32 right: taffy::style::LengthPercentageAuto::Length(5f32),
33 top: taffy::style::LengthPercentageAuto::Length(5f32),
34 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
35 },
36 padding: taffy::geometry::Rect {
37 left: taffy::style::LengthPercentage::Percent(0.03f32),
38 right: taffy::style::LengthPercentage::Percent(0.03f32),
39 top: taffy::style::LengthPercentage::Percent(0.03f32),
40 bottom: taffy::style::LengthPercentage::Percent(0.03f32),
41 },
42 ..Default::default()
43 },
44 &[node000],
45 )
46 .unwrap();
47 let node0 = taffy
48 .new_with_children(
49 taffy::style::Style {
50 display: taffy::style::Display::Grid,
51 min_size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.6f32), height: auto() },
52 margin: taffy::geometry::Rect {
53 left: taffy::style::LengthPercentageAuto::Length(5f32),
54 right: taffy::style::LengthPercentageAuto::Length(5f32),
55 top: taffy::style::LengthPercentageAuto::Length(5f32),
56 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
57 },
58 padding: taffy::geometry::Rect {
59 left: taffy::style::LengthPercentage::Length(3f32),
60 right: taffy::style::LengthPercentage::Length(3f32),
61 top: taffy::style::LengthPercentage::Length(3f32),
62 bottom: taffy::style::LengthPercentage::Length(3f32),
63 },
64 ..Default::default()
65 },
66 &[node00],
67 )
68 .unwrap();
69 let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
70 let node = taffy
71 .new_with_children(
72 taffy::style::Style {
73 display: taffy::style::Display::Grid,
74 grid_template_rows: vec![fr(1f32), fr(4f32)],
75 size: taffy::geometry::Size {
76 width: taffy::style::Dimension::Length(200f32),
77 height: taffy::style::Dimension::Length(200f32),
78 },
79 ..Default::default()
80 },
81 &[node0, node1],
82 )
83 .unwrap();
84 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
85 println!("\nComputed tree:");
86 taffy.print_tree(node);
87 println!();
88 let layout = taffy.layout(node).unwrap();
89 let Layout { size, location, .. } = layout;
90 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
91 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
92 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
93 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
94 let layout = taffy.layout(node0).unwrap();
95 let Layout { size, location, .. } = layout;
96 assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node0, 190f32, size.width);
97 assert_eq!(size.height, 41f32, "height of node {:?}. Expected {}. Actual {}", node0, 41f32, size.height);
98 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
99 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
100 let layout = taffy.layout(node00).unwrap();
101 let Layout { size, location, .. } = layout;
102 assert_eq!(size.width, 92f32, "width of node {:?}. Expected {}. Actual {}", node00, 92f32, size.width);
103 assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node00, 25f32, size.height);
104 assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node00, 8f32, location.x);
105 assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node00, 8f32, location.y);
106 let layout = taffy.layout(node000).unwrap();
107 let Layout { size, location, .. } = layout;
108 assert_eq!(size.width, 36f32, "width of node {:?}. Expected {}. Actual {}", node000, 36f32, size.width);
109 assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node000, 6f32, size.height);
110 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node000, 10f32, location.x);
111 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node000, 10f32, location.y);
112 let layout = taffy.layout(node1).unwrap();
113 let Layout { size, location, .. } = layout;
114 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width);
115 assert_eq!(size.height, 149f32, "height of node {:?}. Expected {}. Actual {}", node1, 149f32, size.height);
116 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
117 assert_eq!(location.y, 51f32, "y of node {:?}. Expected {}. Actual {}", node1, 51f32, location.y);
118}
119
120#[test]
121#[allow(non_snake_case)]
122fn grid_percent_items_nested_with_padding_margin__content_box() {
123 #[allow(unused_imports)]
124 use taffy::{prelude::*, Layout};
125 let mut taffy = crate::new_test_tree();
126 let node000 = taffy
127 .new_leaf(taffy::style::Style {
128 box_sizing: taffy::style::BoxSizing::ContentBox,
129 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
130 margin: taffy::geometry::Rect {
131 left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
132 right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
133 top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
134 bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
135 },
136 padding: taffy::geometry::Rect {
137 left: taffy::style::LengthPercentage::Length(3f32),
138 right: taffy::style::LengthPercentage::Length(3f32),
139 top: taffy::style::LengthPercentage::Length(3f32),
140 bottom: taffy::style::LengthPercentage::Length(3f32),
141 },
142 ..Default::default()
143 })
144 .unwrap();
145 let node00 = taffy
146 .new_with_children(
147 taffy::style::Style {
148 display: taffy::style::Display::Grid,
149 box_sizing: taffy::style::BoxSizing::ContentBox,
150 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
151 margin: taffy::geometry::Rect {
152 left: taffy::style::LengthPercentageAuto::Length(5f32),
153 right: taffy::style::LengthPercentageAuto::Length(5f32),
154 top: taffy::style::LengthPercentageAuto::Length(5f32),
155 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
156 },
157 padding: taffy::geometry::Rect {
158 left: taffy::style::LengthPercentage::Percent(0.03f32),
159 right: taffy::style::LengthPercentage::Percent(0.03f32),
160 top: taffy::style::LengthPercentage::Percent(0.03f32),
161 bottom: taffy::style::LengthPercentage::Percent(0.03f32),
162 },
163 ..Default::default()
164 },
165 &[node000],
166 )
167 .unwrap();
168 let node0 = taffy
169 .new_with_children(
170 taffy::style::Style {
171 display: taffy::style::Display::Grid,
172 box_sizing: taffy::style::BoxSizing::ContentBox,
173 min_size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.6f32), height: auto() },
174 margin: taffy::geometry::Rect {
175 left: taffy::style::LengthPercentageAuto::Length(5f32),
176 right: taffy::style::LengthPercentageAuto::Length(5f32),
177 top: taffy::style::LengthPercentageAuto::Length(5f32),
178 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
179 },
180 padding: taffy::geometry::Rect {
181 left: taffy::style::LengthPercentage::Length(3f32),
182 right: taffy::style::LengthPercentage::Length(3f32),
183 top: taffy::style::LengthPercentage::Length(3f32),
184 bottom: taffy::style::LengthPercentage::Length(3f32),
185 },
186 ..Default::default()
187 },
188 &[node00],
189 )
190 .unwrap();
191 let node1 = taffy
192 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
193 .unwrap();
194 let node = taffy
195 .new_with_children(
196 taffy::style::Style {
197 display: taffy::style::Display::Grid,
198 box_sizing: taffy::style::BoxSizing::ContentBox,
199 grid_template_rows: vec![fr(1f32), fr(4f32)],
200 size: taffy::geometry::Size {
201 width: taffy::style::Dimension::Length(200f32),
202 height: taffy::style::Dimension::Length(200f32),
203 },
204 ..Default::default()
205 },
206 &[node0, node1],
207 )
208 .unwrap();
209 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
210 println!("\nComputed tree:");
211 taffy.print_tree(node);
212 println!();
213 let layout = taffy.layout(node).unwrap();
214 let Layout { size, location, .. } = layout;
215 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
216 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
217 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
218 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
219 let layout = taffy.layout(node0).unwrap();
220 let Layout { size, location, .. } = layout;
221 assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node0, 190f32, size.width);
222 assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node0, 42f32, size.height);
223 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
224 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
225 let layout = taffy.layout(node00).unwrap();
226 let Layout { size, location, .. } = layout;
227 assert_eq!(size.width, 103f32, "width of node {:?}. Expected {}. Actual {}", node00, 103f32, size.width);
228 assert_eq!(size.height, 26f32, "height of node {:?}. Expected {}. Actual {}", node00, 26f32, size.height);
229 assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node00, 8f32, location.x);
230 assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node00, 8f32, location.y);
231 let layout = taffy.layout(node000).unwrap();
232 let Layout { size, location, .. } = layout;
233 assert_eq!(size.width, 48f32, "width of node {:?}. Expected {}. Actual {}", node000, 48f32, size.width);
234 assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node000, 6f32, size.height);
235 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node000, 10f32, location.x);
236 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node000, 10f32, location.y);
237 let layout = taffy.layout(node1).unwrap();
238 let Layout { size, location, .. } = layout;
239 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width);
240 assert_eq!(size.height, 148f32, "height of node {:?}. Expected {}. Actual {}", node1, 148f32, size.height);
241 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
242 assert_eq!(location.y, 52f32, "y of node {:?}. Expected {}. Actual {}", node1, 52f32, location.y);
243}