tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definiciones

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/align_baseline_nested_column.rs Rust · 102 líneas · 5.6 KB Historia Quién tocó qué crudo

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

1#[test]
2fn align_baseline_nested_column() {
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 {
10                width: taffy::style::Dimension::Points(50f32),
11                height: taffy::style::Dimension::Points(60f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node100 = taffy
17        .new_leaf(taffy::style::Style {
18            flex_direction: taffy::style::FlexDirection::Column,
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::Points(50f32),
21                height: taffy::style::Dimension::Points(30f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node101 = taffy
27        .new_leaf(taffy::style::Style {
28            flex_direction: taffy::style::FlexDirection::Column,
29            size: taffy::geometry::Size {
30                width: taffy::style::Dimension::Points(50f32),
31                height: taffy::style::Dimension::Points(40f32),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node10 = taffy
37        .new_with_children(
38            taffy::style::Style {
39                flex_direction: taffy::style::FlexDirection::Column,
40                size: taffy::geometry::Size {
41                    width: taffy::style::Dimension::Points(50f32),
42                    height: taffy::style::Dimension::Points(80f32),
43                },
44                ..Default::default()
45            },
46            &[node100, node101],
47        )
48        .unwrap();
49    let node1 = taffy
50        .new_with_children(
51            taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, ..Default::default() },
52            &[node10],
53        )
54        .unwrap();
55    let node = taffy
56        .new_with_children(
57            taffy::style::Style {
58                align_items: Some(taffy::style::AlignItems::Baseline),
59                size: taffy::geometry::Size {
60                    width: taffy::style::Dimension::Points(100f32),
61                    height: taffy::style::Dimension::Points(100f32),
62                },
63                ..Default::default()
64            },
65            &[node0, node1],
66        )
67        .unwrap();
68    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
69    println!("\nComputed tree:");
70    taffy::debug::print_tree(&taffy, node);
71    println!();
72    let Layout { size, location, .. } = taffy.layout(node).unwrap();
73    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
74    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
77    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
78    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
79    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
82    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
83    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
84    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 80f32, size.height);
85    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, location.x);
86    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, location.y);
87    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
88    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 50f32, size.width);
89    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 80f32, size.height);
90    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
91    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
92    let Layout { size, location, .. } = taffy.layout(node100).unwrap();
93    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node100.data(), 50f32, size.width);
94    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node100.data(), 30f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node100.data(), 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node100.data(), 0f32, location.y);
97    let Layout { size, location, .. } = taffy.layout(node101).unwrap();
98    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node101.data(), 50f32, size.width);
99    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node101.data(), 40f32, size.height);
100    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node101.data(), 0f32, location.x);
101    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node101.data(), 30f32, location.y);
102}