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