gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Sutichaykuna

⎇ 0.3.x tests/generated/align_items_center_justify_content_center.rs Rust · 95 siq'ikuna · 4.9 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn align_items_center_justify_content_center() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node000 = taffy
8        .new_leaf_with_measure(
9            taffy::style::Style {
10                size: taffy::geometry::Size {
11                    width: taffy::style::Dimension::Points(10f32),
12                    height: taffy::style::Dimension::Points(10f32),
13                },
14                ..Default::default()
15            },
16            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
17                const TEXT: &str = "\n      ";
18                super::measure_standard_text(
19                    known_dimensions,
20                    available_space,
21                    TEXT,
22                    super::WritingMode::Horizontal,
23                    None,
24                )
25            }),
26        )
27        .unwrap();
28    let node00 = taffy
29        .new_with_children(
30            taffy::style::Style {
31                flex_direction: taffy::style::FlexDirection::Column,
32                align_items: Some(taffy::style::AlignItems::Center),
33                justify_content: Some(taffy::style::JustifyContent::Center),
34                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(1f32) },
35                margin: taffy::geometry::Rect {
36                    left: taffy::style::LengthPercentageAuto::Points(10f32),
37                    right: taffy::style::LengthPercentageAuto::Points(10f32),
38                    top: zero(),
39                    bottom: zero(),
40                },
41                ..Default::default()
42            },
43            &[node000],
44        )
45        .unwrap();
46    let node0 = taffy
47        .new_with_children(
48            taffy::style::Style {
49                flex_direction: taffy::style::FlexDirection::Column,
50                align_items: Some(taffy::style::AlignItems::Center),
51                justify_content: Some(taffy::style::JustifyContent::Center),
52                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) },
53                ..Default::default()
54            },
55            &[node00],
56        )
57        .unwrap();
58    let node = taffy
59        .new_with_children(
60            taffy::style::Style {
61                flex_direction: taffy::style::FlexDirection::Column,
62                size: taffy::geometry::Size {
63                    width: taffy::style::Dimension::Points(500f32),
64                    height: taffy::style::Dimension::Points(500f32),
65                },
66                ..Default::default()
67            },
68            &[node0],
69        )
70        .unwrap();
71    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
72    println!("\nComputed tree:");
73    taffy::debug::print_tree(&taffy, node);
74    println!();
75    let Layout { size, location, .. } = taffy.layout(node).unwrap();
76    assert_eq!(size.width, 500f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 500f32, size.width);
77    assert_eq!(size.height, 500f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 500f32, size.height);
78    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
79    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
80    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
81    assert_eq!(size.width, 500f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 500f32, size.width);
82    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
85    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
86    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, size.width);
87    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 50f32, size.height);
88    assert_eq!(location.x, 245f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 245f32, location.x);
89    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
90    let Layout { size, location, .. } = taffy.layout(node000).unwrap();
91    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node000.data(), 10f32, size.width);
92    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000.data(), 10f32, size.height);
93    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.x);
94    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node000.data(), 20f32, location.y);
95}