gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94524 Sutichaykuna

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/align_content_spacearound.rs Rust · 100 siq'ikuna · 5.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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