gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 238Markdown 7TOML 31453 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/align_baseline_child_multiline.rs Rust · 110 siq'ikuna · 5.9 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename `Points`/`points` to `Length`/`length` in many APIs (#459) 55abeaf2e · Simon Sapin ·

1#[test]
2fn align_baseline_child_multiline() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(50f32),
10                height: taffy::style::Dimension::Length(60f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node10 = taffy
16        .new_leaf(taffy::style::Style {
17            size: taffy::geometry::Size {
18                width: taffy::style::Dimension::Length(25f32),
19                height: taffy::style::Dimension::Length(20f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node11 = taffy
25        .new_leaf(taffy::style::Style {
26            size: taffy::geometry::Size {
27                width: taffy::style::Dimension::Length(25f32),
28                height: taffy::style::Dimension::Length(10f32),
29            },
30            ..Default::default()
31        })
32        .unwrap();
33    let node12 = taffy
34        .new_leaf(taffy::style::Style {
35            size: taffy::geometry::Size {
36                width: taffy::style::Dimension::Length(25f32),
37                height: taffy::style::Dimension::Length(20f32),
38            },
39            ..Default::default()
40        })
41        .unwrap();
42    let node13 = taffy
43        .new_leaf(taffy::style::Style {
44            size: taffy::geometry::Size {
45                width: taffy::style::Dimension::Length(25f32),
46                height: taffy::style::Dimension::Length(10f32),
47            },
48            ..Default::default()
49        })
50        .unwrap();
51    let node1 = taffy
52        .new_with_children(
53            taffy::style::Style {
54                flex_wrap: taffy::style::FlexWrap::Wrap,
55                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
56                ..Default::default()
57            },
58            &[node10, node11, node12, node13],
59        )
60        .unwrap();
61    let node = taffy
62        .new_with_children(
63            taffy::style::Style {
64                align_items: Some(taffy::style::AlignItems::Baseline),
65                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
66                ..Default::default()
67            },
68            &[node0, node1],
69        )
70        .unwrap();
71    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
72    println!("\nComputed tree:");
73    taffy::util::print_tree(&taffy, node);
74    println!();
75    let Layout { size, location, .. } = taffy.layout(node).unwrap();
76    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
77    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node, 80f32, size.height);
78    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
79    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
80    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
81    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
82    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0, 60f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
85    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
86    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
87    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
88    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
89    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
90    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
91    assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node10, 25f32, size.width);
92    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node10, 20f32, size.height);
93    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
94    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
95    let Layout { size, location, .. } = taffy.layout(node11).unwrap();
96    assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node11, 25f32, size.width);
97    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node11, 10f32, size.height);
98    assert_eq!(location.x, 25f32, "x of node {:?}. Expected {}. Actual {}", node11, 25f32, location.x);
99    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node11, 0f32, location.y);
100    let Layout { size, location, .. } = taffy.layout(node12).unwrap();
101    assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node12, 25f32, size.width);
102    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node12, 20f32, size.height);
103    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node12, 0f32, location.x);
104    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node12, 20f32, location.y);
105    let Layout { size, location, .. } = taffy.layout(node13).unwrap();
106    assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node13, 25f32, size.width);
107    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node13, 10f32, size.height);
108    assert_eq!(location.x, 25f32, "x of node {:?}. Expected {}. Actual {}", node13, 25f32, location.x);
109    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node13, 20f32, location.y);
110}