gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 717HTML 669Markdown 12TOML 62373 Sutichaykuna

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/align_baseline_multiline_column.rs Rust · 520 siq'ikuna · 20.7 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn align_baseline_multiline_column__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(50f32),
11                height: taffy::style::Dimension::Length(50f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node10 = taffy
17        .new_leaf(taffy::style::Style {
18            size: taffy::geometry::Size {
19                width: taffy::style::Dimension::Length(20f32),
20                height: taffy::style::Dimension::Length(20f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node1 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                flex_direction: taffy::style::FlexDirection::Column,
29                size: taffy::geometry::Size {
30                    width: taffy::style::Dimension::Length(30f32),
31                    height: taffy::style::Dimension::Length(50f32),
32                },
33                ..Default::default()
34            },
35            &[node10],
36        )
37        .unwrap();
38    let node20 = taffy
39        .new_leaf(taffy::style::Style {
40            size: taffy::geometry::Size {
41                width: taffy::style::Dimension::Length(10f32),
42                height: taffy::style::Dimension::Length(10f32),
43            },
44            ..Default::default()
45        })
46        .unwrap();
47    let node2 = taffy
48        .new_with_children(
49            taffy::style::Style {
50                flex_direction: taffy::style::FlexDirection::Column,
51                size: taffy::geometry::Size {
52                    width: taffy::style::Dimension::Length(40f32),
53                    height: taffy::style::Dimension::Length(70f32),
54                },
55                ..Default::default()
56            },
57            &[node20],
58        )
59        .unwrap();
60    let node3 = taffy
61        .new_leaf(taffy::style::Style {
62            size: taffy::geometry::Size {
63                width: taffy::style::Dimension::Length(50f32),
64                height: taffy::style::Dimension::Length(20f32),
65            },
66            ..Default::default()
67        })
68        .unwrap();
69    let node = taffy
70        .new_with_children(
71            taffy::style::Style {
72                flex_direction: taffy::style::FlexDirection::Column,
73                flex_wrap: taffy::style::FlexWrap::Wrap,
74                align_items: Some(taffy::style::AlignItems::Baseline),
75                size: taffy::geometry::Size {
76                    width: taffy::style::Dimension::Length(100f32),
77                    height: taffy::style::Dimension::Length(100f32),
78                },
79                ..Default::default()
80            },
81            &[node0, node1, node2, node3],
82        )
83        .unwrap();
84    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
85    println!("\nComputed tree:");
86    taffy.print_tree(node);
87    println!();
88    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
89    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
90    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
91    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
92    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
93    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
94    #[cfg(feature = "content_size")]
95    assert_eq!(
96        layout.scroll_width(),
97        0f32,
98        "scroll_width of node {:?}. Expected {}. Actual {}",
99        node,
100        0f32,
101        layout.scroll_width()
102    );
103    #[cfg(feature = "content_size")]
104    assert_eq!(
105        layout.scroll_height(),
106        0f32,
107        "scroll_height of node {:?}. Expected {}. Actual {}",
108        node,
109        0f32,
110        layout.scroll_height()
111    );
112    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
113    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
114    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
115    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
116    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
117    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
118    #[cfg(feature = "content_size")]
119    assert_eq!(
120        layout.scroll_width(),
121        0f32,
122        "scroll_width of node {:?}. Expected {}. Actual {}",
123        node0,
124        0f32,
125        layout.scroll_width()
126    );
127    #[cfg(feature = "content_size")]
128    assert_eq!(
129        layout.scroll_height(),
130        0f32,
131        "scroll_height of node {:?}. Expected {}. Actual {}",
132        node0,
133        0f32,
134        layout.scroll_height()
135    );
136    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
137    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
138    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width);
139    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
140    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
141    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
142    #[cfg(feature = "content_size")]
143    assert_eq!(
144        layout.scroll_width(),
145        0f32,
146        "scroll_width of node {:?}. Expected {}. Actual {}",
147        node1,
148        0f32,
149        layout.scroll_width()
150    );
151    #[cfg(feature = "content_size")]
152    assert_eq!(
153        layout.scroll_height(),
154        0f32,
155        "scroll_height of node {:?}. Expected {}. Actual {}",
156        node1,
157        0f32,
158        layout.scroll_height()
159    );
160    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
161    let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
162    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node10, 20f32, size.width);
163    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node10, 20f32, size.height);
164    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
165    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
166    #[cfg(feature = "content_size")]
167    assert_eq!(
168        layout.scroll_width(),
169        0f32,
170        "scroll_width of node {:?}. Expected {}. Actual {}",
171        node10,
172        0f32,
173        layout.scroll_width()
174    );
175    #[cfg(feature = "content_size")]
176    assert_eq!(
177        layout.scroll_height(),
178        0f32,
179        "scroll_height of node {:?}. Expected {}. Actual {}",
180        node10,
181        0f32,
182        layout.scroll_height()
183    );
184    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
185    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
186    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
187    assert_eq!(size.height, 70f32, "height of node {:?}. Expected {}. Actual {}", node2, 70f32, size.height);
188    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
189    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
190    #[cfg(feature = "content_size")]
191    assert_eq!(
192        layout.scroll_width(),
193        0f32,
194        "scroll_width of node {:?}. Expected {}. Actual {}",
195        node2,
196        0f32,
197        layout.scroll_width()
198    );
199    #[cfg(feature = "content_size")]
200    assert_eq!(
201        layout.scroll_height(),
202        0f32,
203        "scroll_height of node {:?}. Expected {}. Actual {}",
204        node2,
205        0f32,
206        layout.scroll_height()
207    );
208    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
209    let layout @ Layout { size, location, .. } = taffy.layout(node20).unwrap();
210    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node20, 10f32, size.width);
211    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
212    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20, 0f32, location.x);
213    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y);
214    #[cfg(feature = "content_size")]
215    assert_eq!(
216        layout.scroll_width(),
217        0f32,
218        "scroll_width of node {:?}. Expected {}. Actual {}",
219        node20,
220        0f32,
221        layout.scroll_width()
222    );
223    #[cfg(feature = "content_size")]
224    assert_eq!(
225        layout.scroll_height(),
226        0f32,
227        "scroll_height of node {:?}. Expected {}. Actual {}",
228        node20,
229        0f32,
230        layout.scroll_height()
231    );
232    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
233    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
234    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
235    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
236    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
237    assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node3, 70f32, location.y);
238    #[cfg(feature = "content_size")]
239    assert_eq!(
240        layout.scroll_width(),
241        0f32,
242        "scroll_width of node {:?}. Expected {}. Actual {}",
243        node3,
244        0f32,
245        layout.scroll_width()
246    );
247    #[cfg(feature = "content_size")]
248    assert_eq!(
249        layout.scroll_height(),
250        0f32,
251        "scroll_height of node {:?}. Expected {}. Actual {}",
252        node3,
253        0f32,
254        layout.scroll_height()
255    );
256}
257
258#[test]
259#[allow(non_snake_case)]
260fn align_baseline_multiline_column__content_box() {
261    #[allow(unused_imports)]
262    use taffy::{prelude::*, tree::Layout, TaffyTree};
263    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
264    let node0 = taffy
265        .new_leaf(taffy::style::Style {
266            box_sizing: taffy::style::BoxSizing::ContentBox,
267            size: taffy::geometry::Size {
268                width: taffy::style::Dimension::Length(50f32),
269                height: taffy::style::Dimension::Length(50f32),
270            },
271            ..Default::default()
272        })
273        .unwrap();
274    let node10 = taffy
275        .new_leaf(taffy::style::Style {
276            box_sizing: taffy::style::BoxSizing::ContentBox,
277            size: taffy::geometry::Size {
278                width: taffy::style::Dimension::Length(20f32),
279                height: taffy::style::Dimension::Length(20f32),
280            },
281            ..Default::default()
282        })
283        .unwrap();
284    let node1 = taffy
285        .new_with_children(
286            taffy::style::Style {
287                box_sizing: taffy::style::BoxSizing::ContentBox,
288                flex_direction: taffy::style::FlexDirection::Column,
289                size: taffy::geometry::Size {
290                    width: taffy::style::Dimension::Length(30f32),
291                    height: taffy::style::Dimension::Length(50f32),
292                },
293                ..Default::default()
294            },
295            &[node10],
296        )
297        .unwrap();
298    let node20 = taffy
299        .new_leaf(taffy::style::Style {
300            box_sizing: taffy::style::BoxSizing::ContentBox,
301            size: taffy::geometry::Size {
302                width: taffy::style::Dimension::Length(10f32),
303                height: taffy::style::Dimension::Length(10f32),
304            },
305            ..Default::default()
306        })
307        .unwrap();
308    let node2 = taffy
309        .new_with_children(
310            taffy::style::Style {
311                box_sizing: taffy::style::BoxSizing::ContentBox,
312                flex_direction: taffy::style::FlexDirection::Column,
313                size: taffy::geometry::Size {
314                    width: taffy::style::Dimension::Length(40f32),
315                    height: taffy::style::Dimension::Length(70f32),
316                },
317                ..Default::default()
318            },
319            &[node20],
320        )
321        .unwrap();
322    let node3 = taffy
323        .new_leaf(taffy::style::Style {
324            box_sizing: taffy::style::BoxSizing::ContentBox,
325            size: taffy::geometry::Size {
326                width: taffy::style::Dimension::Length(50f32),
327                height: taffy::style::Dimension::Length(20f32),
328            },
329            ..Default::default()
330        })
331        .unwrap();
332    let node = taffy
333        .new_with_children(
334            taffy::style::Style {
335                box_sizing: taffy::style::BoxSizing::ContentBox,
336                flex_direction: taffy::style::FlexDirection::Column,
337                flex_wrap: taffy::style::FlexWrap::Wrap,
338                align_items: Some(taffy::style::AlignItems::Baseline),
339                size: taffy::geometry::Size {
340                    width: taffy::style::Dimension::Length(100f32),
341                    height: taffy::style::Dimension::Length(100f32),
342                },
343                ..Default::default()
344            },
345            &[node0, node1, node2, node3],
346        )
347        .unwrap();
348    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
349    println!("\nComputed tree:");
350    taffy.print_tree(node);
351    println!();
352    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
353    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
354    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
355    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
356    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
357    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
358    #[cfg(feature = "content_size")]
359    assert_eq!(
360        layout.scroll_width(),
361        0f32,
362        "scroll_width of node {:?}. Expected {}. Actual {}",
363        node,
364        0f32,
365        layout.scroll_width()
366    );
367    #[cfg(feature = "content_size")]
368    assert_eq!(
369        layout.scroll_height(),
370        0f32,
371        "scroll_height of node {:?}. Expected {}. Actual {}",
372        node,
373        0f32,
374        layout.scroll_height()
375    );
376    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
377    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
378    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
379    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
380    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
381    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
382    #[cfg(feature = "content_size")]
383    assert_eq!(
384        layout.scroll_width(),
385        0f32,
386        "scroll_width of node {:?}. Expected {}. Actual {}",
387        node0,
388        0f32,
389        layout.scroll_width()
390    );
391    #[cfg(feature = "content_size")]
392    assert_eq!(
393        layout.scroll_height(),
394        0f32,
395        "scroll_height of node {:?}. Expected {}. Actual {}",
396        node0,
397        0f32,
398        layout.scroll_height()
399    );
400    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
401    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
402    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width);
403    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
404    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
405    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
406    #[cfg(feature = "content_size")]
407    assert_eq!(
408        layout.scroll_width(),
409        0f32,
410        "scroll_width of node {:?}. Expected {}. Actual {}",
411        node1,
412        0f32,
413        layout.scroll_width()
414    );
415    #[cfg(feature = "content_size")]
416    assert_eq!(
417        layout.scroll_height(),
418        0f32,
419        "scroll_height of node {:?}. Expected {}. Actual {}",
420        node1,
421        0f32,
422        layout.scroll_height()
423    );
424    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
425    let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
426    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node10, 20f32, size.width);
427    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node10, 20f32, size.height);
428    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
429    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
430    #[cfg(feature = "content_size")]
431    assert_eq!(
432        layout.scroll_width(),
433        0f32,
434        "scroll_width of node {:?}. Expected {}. Actual {}",
435        node10,
436        0f32,
437        layout.scroll_width()
438    );
439    #[cfg(feature = "content_size")]
440    assert_eq!(
441        layout.scroll_height(),
442        0f32,
443        "scroll_height of node {:?}. Expected {}. Actual {}",
444        node10,
445        0f32,
446        layout.scroll_height()
447    );
448    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
449    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
450    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
451    assert_eq!(size.height, 70f32, "height of node {:?}. Expected {}. Actual {}", node2, 70f32, size.height);
452    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
453    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
454    #[cfg(feature = "content_size")]
455    assert_eq!(
456        layout.scroll_width(),
457        0f32,
458        "scroll_width of node {:?}. Expected {}. Actual {}",
459        node2,
460        0f32,
461        layout.scroll_width()
462    );
463    #[cfg(feature = "content_size")]
464    assert_eq!(
465        layout.scroll_height(),
466        0f32,
467        "scroll_height of node {:?}. Expected {}. Actual {}",
468        node2,
469        0f32,
470        layout.scroll_height()
471    );
472    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
473    let layout @ Layout { size, location, .. } = taffy.layout(node20).unwrap();
474    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node20, 10f32, size.width);
475    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
476    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20, 0f32, location.x);
477    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y);
478    #[cfg(feature = "content_size")]
479    assert_eq!(
480        layout.scroll_width(),
481        0f32,
482        "scroll_width of node {:?}. Expected {}. Actual {}",
483        node20,
484        0f32,
485        layout.scroll_width()
486    );
487    #[cfg(feature = "content_size")]
488    assert_eq!(
489        layout.scroll_height(),
490        0f32,
491        "scroll_height of node {:?}. Expected {}. Actual {}",
492        node20,
493        0f32,
494        layout.scroll_height()
495    );
496    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
497    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
498    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
499    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
500    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
501    assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node3, 70f32, location.y);
502    #[cfg(feature = "content_size")]
503    assert_eq!(
504        layout.scroll_width(),
505        0f32,
506        "scroll_width of node {:?}. Expected {}. Actual {}",
507        node3,
508        0f32,
509        layout.scroll_width()
510    );
511    #[cfg(feature = "content_size")]
512    assert_eq!(
513        layout.scroll_height(),
514        0f32,
515        "scroll_height of node {:?}. Expected {}. Actual {}",
516        node3,
517        0f32,
518        layout.scroll_height()
519    );
520}