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