tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 238Markdown 7TOML 31234 Definiciones

⎇ ae87fd0283feff32a5ceffe4c77394ff6ca88d39 tests/generated/grid_align_items_baseline_nested_column.rs Rust · 104 líneas · 5.6 KB Historia Quién tocó qué crudo

Grid: baseline alignment support (#344) ab747b81e · Nico Burns ·

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