gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Sutichaykuna

⎇ 48e4800f14c6af5cd26275fb570d11b93e279654 tests/generated/flex/align_items_center_justify_content_center.rs Rust · 94 siq'ikuna · 4.7 KB Ñawpa willay Pi imata llamkarqan ch'uya

Make test measure function non-generated (move to tests/fixtures.rs) (#529) 4fb530bdd · Nico Burns ·

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