tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Sutichaykuna

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