tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

⎇ b91874d4e34ecc9054b468a338ffcae6f61a1b4a tests/generated/align_baseline_child_multiline_override.rs Rust · 119 lines · 6.5 KB History Who touched what raw

Fix flexbox baseline alignment (#325) b91874d4e · Nico Burns ·

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