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_column2.rs Rust · 127 líneas · 6.8 KB Historia Quién tocó qué crudo

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

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