gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Sutichaykuna

⎇ 0.3.x tests/generated/align_content_flex_start_without_height_on_children.rs Rust · 92 siq'ikuna · 5.3 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_without_height_on_children() {
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 {
16                width: taffy::style::Dimension::Points(50f32),
17                height: taffy::style::Dimension::Points(10f32),
18            },
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            size: taffy::geometry::Size {
31                width: taffy::style::Dimension::Points(50f32),
32                height: taffy::style::Dimension::Points(10f32),
33            },
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_direction: taffy::style::FlexDirection::Column,
47                flex_wrap: taffy::style::FlexWrap::Wrap,
48                align_content: Some(taffy::style::AlignContent::FlexStart),
49                size: taffy::geometry::Size {
50                    width: taffy::style::Dimension::Points(100f32),
51                    height: taffy::style::Dimension::Points(100f32),
52                },
53                ..Default::default()
54            },
55            &[node0, node1, node2, node3, node4],
56        )
57        .unwrap();
58    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
59    println!("\nComputed tree:");
60    taffy::debug::print_tree(&taffy, node);
61    println!();
62    let Layout { size, location, .. } = taffy.layout(node).unwrap();
63    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
64    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
65    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
66    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
67    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
68    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
69    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, size.height);
70    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
71    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
72    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
73    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
74    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 10f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
77    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
78    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width);
79    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
81    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 10f32, location.y);
82    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
83    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.width);
84    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 10f32, size.height);
85    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.x);
86    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 10f32, location.y);
87    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
88    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 50f32, size.width);
89    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 0f32, size.height);
90    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 0f32, location.x);
91    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, location.y);
92}