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