gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

⎇ 0.3.x tests/generated/align_baseline_child_multiline.rs Rust · 111 líneas · 6.2 KB Historia Quién tocó qué crudo

Better assert messages (#290) 2b7d63a03 · Nico Burns ·

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