gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definitions

⎇ 0.4.x tests/generated/grid/grid_max_content_maximum_single_item.rs Rust · 279 lines · 11.9 KB History Who touched what raw

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn grid_max_content_maximum_single_item() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
7    let node1 = taffy
8        .new_leaf_with_context(
9            taffy::style::Style { ..Default::default() },
10            crate::TextMeasure {
11                text_content: "HH\u{200b}HH",
12                writing_mode: crate::WritingMode::Horizontal,
13                _aspect_ratio: None,
14            },
15        )
16        .unwrap();
17    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21    let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
22    let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
23    let node8 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
24    let node = taffy
25        .new_with_children(
26            taffy::style::Style {
27                display: taffy::style::Display::Grid,
28                grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
29                grid_template_columns: vec![length(40f32), minmax(length(0f32), max_content()), length(40f32)],
30                ..Default::default()
31            },
32            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
33        )
34        .unwrap();
35    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
36    println!("\nComputed tree:");
37    taffy.print_tree(node);
38    println!();
39    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
40    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
41    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
42    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
43    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
44    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
45    #[cfg(feature = "content_size")]
46    assert_eq!(
47        layout.scroll_width(),
48        0f32,
49        "scroll_width of node {:?}. Expected {}. Actual {}",
50        node,
51        0f32,
52        layout.scroll_width()
53    );
54    #[cfg(feature = "content_size")]
55    assert_eq!(
56        layout.scroll_height(),
57        0f32,
58        "scroll_height of node {:?}. Expected {}. Actual {}",
59        node,
60        0f32,
61        layout.scroll_height()
62    );
63    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
64    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
65    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
66    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
67    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
68    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
69    #[cfg(feature = "content_size")]
70    assert_eq!(
71        layout.scroll_width(),
72        0f32,
73        "scroll_width of node {:?}. Expected {}. Actual {}",
74        node0,
75        0f32,
76        layout.scroll_width()
77    );
78    #[cfg(feature = "content_size")]
79    assert_eq!(
80        layout.scroll_height(),
81        0f32,
82        "scroll_height of node {:?}. Expected {}. Actual {}",
83        node0,
84        0f32,
85        layout.scroll_height()
86    );
87    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
88    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
89    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
90    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
91    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
92    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
93    #[cfg(feature = "content_size")]
94    assert_eq!(
95        layout.scroll_width(),
96        0f32,
97        "scroll_width of node {:?}. Expected {}. Actual {}",
98        node1,
99        0f32,
100        layout.scroll_width()
101    );
102    #[cfg(feature = "content_size")]
103    assert_eq!(
104        layout.scroll_height(),
105        0f32,
106        "scroll_height of node {:?}. Expected {}. Actual {}",
107        node1,
108        0f32,
109        layout.scroll_height()
110    );
111    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
112    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
113    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
114    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
115    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
116    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
117    #[cfg(feature = "content_size")]
118    assert_eq!(
119        layout.scroll_width(),
120        0f32,
121        "scroll_width of node {:?}. Expected {}. Actual {}",
122        node2,
123        0f32,
124        layout.scroll_width()
125    );
126    #[cfg(feature = "content_size")]
127    assert_eq!(
128        layout.scroll_height(),
129        0f32,
130        "scroll_height of node {:?}. Expected {}. Actual {}",
131        node2,
132        0f32,
133        layout.scroll_height()
134    );
135    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
136    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
137    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
138    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
139    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
140    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
141    #[cfg(feature = "content_size")]
142    assert_eq!(
143        layout.scroll_width(),
144        0f32,
145        "scroll_width of node {:?}. Expected {}. Actual {}",
146        node3,
147        0f32,
148        layout.scroll_width()
149    );
150    #[cfg(feature = "content_size")]
151    assert_eq!(
152        layout.scroll_height(),
153        0f32,
154        "scroll_height of node {:?}. Expected {}. Actual {}",
155        node3,
156        0f32,
157        layout.scroll_height()
158    );
159    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
160    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
161    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node4, 40f32, size.width);
162    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
163    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
164    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
165    #[cfg(feature = "content_size")]
166    assert_eq!(
167        layout.scroll_width(),
168        0f32,
169        "scroll_width of node {:?}. Expected {}. Actual {}",
170        node4,
171        0f32,
172        layout.scroll_width()
173    );
174    #[cfg(feature = "content_size")]
175    assert_eq!(
176        layout.scroll_height(),
177        0f32,
178        "scroll_height of node {:?}. Expected {}. Actual {}",
179        node4,
180        0f32,
181        layout.scroll_height()
182    );
183    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
184    let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
185    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node5, 40f32, size.width);
186    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
187    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node5, 80f32, location.x);
188    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
189    #[cfg(feature = "content_size")]
190    assert_eq!(
191        layout.scroll_width(),
192        0f32,
193        "scroll_width of node {:?}. Expected {}. Actual {}",
194        node5,
195        0f32,
196        layout.scroll_width()
197    );
198    #[cfg(feature = "content_size")]
199    assert_eq!(
200        layout.scroll_height(),
201        0f32,
202        "scroll_height of node {:?}. Expected {}. Actual {}",
203        node5,
204        0f32,
205        layout.scroll_height()
206    );
207    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
208    let layout @ Layout { size, location, .. } = taffy.layout(node6).unwrap();
209    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node6, 40f32, size.width);
210    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6, 40f32, size.height);
211    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
212    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
213    #[cfg(feature = "content_size")]
214    assert_eq!(
215        layout.scroll_width(),
216        0f32,
217        "scroll_width of node {:?}. Expected {}. Actual {}",
218        node6,
219        0f32,
220        layout.scroll_width()
221    );
222    #[cfg(feature = "content_size")]
223    assert_eq!(
224        layout.scroll_height(),
225        0f32,
226        "scroll_height of node {:?}. Expected {}. Actual {}",
227        node6,
228        0f32,
229        layout.scroll_height()
230    );
231    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
232    let layout @ Layout { size, location, .. } = taffy.layout(node7).unwrap();
233    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node7, 40f32, size.width);
234    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node7, 40f32, size.height);
235    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
236    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
237    #[cfg(feature = "content_size")]
238    assert_eq!(
239        layout.scroll_width(),
240        0f32,
241        "scroll_width of node {:?}. Expected {}. Actual {}",
242        node7,
243        0f32,
244        layout.scroll_width()
245    );
246    #[cfg(feature = "content_size")]
247    assert_eq!(
248        layout.scroll_height(),
249        0f32,
250        "scroll_height of node {:?}. Expected {}. Actual {}",
251        node7,
252        0f32,
253        layout.scroll_height()
254    );
255    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
256    let layout @ Layout { size, location, .. } = taffy.layout(node8).unwrap();
257    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8, 40f32, size.width);
258    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8, 40f32, size.height);
259    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node8, 80f32, location.x);
260    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
261    #[cfg(feature = "content_size")]
262    assert_eq!(
263        layout.scroll_width(),
264        0f32,
265        "scroll_width of node {:?}. Expected {}. Actual {}",
266        node8,
267        0f32,
268        layout.scroll_width()
269    );
270    #[cfg(feature = "content_size")]
271    assert_eq!(
272        layout.scroll_height(),
273        0f32,
274        "scroll_height of node {:?}. Expected {}. Actual {}",
275        node8,
276        0f32,
277        layout.scroll_height()
278    );
279}