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