tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Sutichaykuna

⎇ 0.3.x tests/generated/align_content_stretch_row_with_margin.rs Rust · 97 siq'ikuna · 5.8 KB Ñawpa willay Pi imata llamkarqan ch'uya

Import yoga tests (#320) e05b9093d · Nico Burns ·

1#[test]
2fn align_content_stretch_row_with_margin() {
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 { width: taffy::style::Dimension::Points(50f32), height: auto() },
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() },
16            margin: taffy::geometry::Rect {
17                left: taffy::style::LengthPercentageAuto::Points(10f32),
18                right: taffy::style::LengthPercentageAuto::Points(10f32),
19                top: taffy::style::LengthPercentageAuto::Points(10f32),
20                bottom: taffy::style::LengthPercentageAuto::Points(10f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node2 = taffy
26        .new_leaf(taffy::style::Style {
27            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() },
28            ..Default::default()
29        })
30        .unwrap();
31    let node3 = taffy
32        .new_leaf(taffy::style::Style {
33            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() },
34            margin: taffy::geometry::Rect {
35                left: taffy::style::LengthPercentageAuto::Points(10f32),
36                right: taffy::style::LengthPercentageAuto::Points(10f32),
37                top: taffy::style::LengthPercentageAuto::Points(10f32),
38                bottom: taffy::style::LengthPercentageAuto::Points(10f32),
39            },
40            ..Default::default()
41        })
42        .unwrap();
43    let node4 = taffy
44        .new_leaf(taffy::style::Style {
45            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() },
46            ..Default::default()
47        })
48        .unwrap();
49    let node = taffy
50        .new_with_children(
51            taffy::style::Style {
52                flex_wrap: taffy::style::FlexWrap::Wrap,
53                align_content: Some(taffy::style::AlignContent::Stretch),
54                size: taffy::geometry::Size {
55                    width: taffy::style::Dimension::Points(150f32),
56                    height: taffy::style::Dimension::Points(100f32),
57                },
58                ..Default::default()
59            },
60            &[node0, node1, node2, node3, node4],
61        )
62        .unwrap();
63    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
64    println!("\nComputed tree:");
65    taffy::debug::print_tree(&taffy, node);
66    println!();
67    let Layout { size, location, .. } = taffy.layout(node).unwrap();
68    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 150f32, size.width);
69    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
70    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
71    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
72    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
73    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
74    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
77    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
78    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
79    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
80    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, location.x);
81    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 10f32, location.y);
82    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
83    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width);
84    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 40f32, size.height);
85    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
86    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 40f32, location.y);
87    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
88    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.width);
89    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 20f32, size.height);
90    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 60f32, location.x);
91    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, location.y);
92    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
93    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 50f32, size.width);
94    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 0f32, location.x);
96    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 80f32, location.y);
97}