gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Sutichaykuna

⎇ 0.3.x tests/generated/simple_child.rs Rust · 112 siq'ikuna · 6.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement §9.9.1. Flex Container Intrinsic Main Sizes (#354) bf3dfaec9 · Nico Burns ·

1#[test]
2fn simple_child() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node000 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Points(10f32),
11                height: taffy::style::Dimension::Points(10f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node00 = taffy
17        .new_with_children(
18            taffy::style::Style {
19                size: taffy::geometry::Size {
20                    width: taffy::style::Dimension::Points(10f32),
21                    height: taffy::style::Dimension::Points(10f32),
22                },
23                ..Default::default()
24            },
25            &[node000],
26        )
27        .unwrap();
28    let node010 = taffy
29        .new_leaf(taffy::style::Style {
30            align_self: Some(taffy::style::AlignSelf::Center),
31            size: taffy::geometry::Size {
32                width: taffy::style::Dimension::Points(10f32),
33                height: taffy::style::Dimension::Points(10f32),
34            },
35            ..Default::default()
36        })
37        .unwrap();
38    let node011 = taffy
39        .new_leaf(taffy::style::Style {
40            align_self: Some(taffy::style::AlignSelf::Center),
41            size: taffy::geometry::Size {
42                width: taffy::style::Dimension::Points(10f32),
43                height: taffy::style::Dimension::Points(10f32),
44            },
45            ..Default::default()
46        })
47        .unwrap();
48    let node01 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node010, node011]).unwrap();
49    let node0 = taffy
50        .new_with_children(
51            taffy::style::Style {
52                size: taffy::geometry::Size {
53                    width: taffy::style::Dimension::Percent(1f32),
54                    height: taffy::style::Dimension::Percent(1f32),
55                },
56                ..Default::default()
57            },
58            &[node00, node01],
59        )
60        .unwrap();
61    let node = taffy
62        .new_with_children(
63            taffy::style::Style {
64                size: taffy::geometry::Size {
65                    width: taffy::style::Dimension::Points(100f32),
66                    height: taffy::style::Dimension::Points(100f32),
67                },
68                ..Default::default()
69            },
70            &[node0],
71        )
72        .unwrap();
73    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
74    println!("\nComputed tree:");
75    taffy::debug::print_tree(&taffy, node);
76    println!();
77    let Layout { size, location, .. } = taffy.layout(node).unwrap();
78    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
79    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
82    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
83    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
84    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height);
85    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
86    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
87    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
88    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, size.width);
89    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, size.height);
90    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
91    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
92    let Layout { size, location, .. } = taffy.layout(node000).unwrap();
93    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node000.data(), 10f32, size.width);
94    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000.data(), 10f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.y);
97    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
98    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, size.width);
99    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 100f32, size.height);
100    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 10f32, location.x);
101    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.y);
102    let Layout { size, location, .. } = taffy.layout(node010).unwrap();
103    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node010.data(), 10f32, size.width);
104    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node010.data(), 10f32, size.height);
105    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node010.data(), 0f32, location.x);
106    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node010.data(), 45f32, location.y);
107    let Layout { size, location, .. } = taffy.layout(node011).unwrap();
108    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node011.data(), 10f32, size.width);
109    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node011.data(), 10f32, size.height);
110    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node011.data(), 10f32, location.x);
111    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node011.data(), 45f32, location.y);
112}