gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94524 Sutichaykuna

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/align_content_stretch_row_with_flex.rs Rust · 91 siq'ikuna · 5.3 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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