gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Sutichaykuna

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/align_content_flex_start_with_flex.rs Rust · 98 siq'ikuna · 5.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

Reinstate FlexStart and FlexEnd alignment variants (#336) 78fd9cc09 · Nico Burns ·

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