tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91822 Sutichaykuna

⎇ 837d03fde9d8a4efa0f4eaf1e8be2fd34a719a50 tests/generated/grid_align_items_baseline_child.rs Rust · 78 siq'ikuna · 4.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn grid_align_items_baseline_child() {
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(50f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node10 = 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(10f32),
23            },
24            ..Default::default()
25        })
26        .unwrap();
27    let node1 = taffy
28        .new_with_children(
29            taffy::style::Style {
30                display: taffy::style::Display::Grid,
31                size: taffy::geometry::Size {
32                    width: taffy::style::Dimension::Points(50f32),
33                    height: taffy::style::Dimension::Points(20f32),
34                },
35                ..Default::default()
36            },
37            &[node10],
38        )
39        .unwrap();
40    let node = taffy
41        .new_with_children(
42            taffy::style::Style {
43                display: taffy::style::Display::Grid,
44                align_items: Some(taffy::style::AlignItems::Baseline),
45                size: taffy::geometry::Size {
46                    width: taffy::style::Dimension::Points(100f32),
47                    height: taffy::style::Dimension::Points(100f32),
48                },
49                ..Default::default()
50            },
51            &[node0, node1],
52        )
53        .unwrap();
54    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
55    println!("\nComputed tree:");
56    taffy::debug::print_tree(&taffy, node);
57    println!();
58    let Layout { size, location, .. } = taffy.layout(node).unwrap();
59    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
60    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
61    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
62    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
63    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
64    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
65    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
66    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
67    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
68    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
69    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
70    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
72    assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 65f32, location.y);
73    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
74    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 50f32, size.width);
75    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 10f32, size.height);
76    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
77    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
78}