gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Definiciones

⎇ 0.3.x tests/generated/align_baseline_multiline_column.rs Rust · 123 líneas · 6.6 KB Historia Quién tocó qué crudo

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

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