tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 238Markdown 7TOML 31453 Definitions

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/grid_absolute_align_self_sized_all.rs Rust · 159 lines · 8.9 KB History Who touched what raw

Rename PositionType and Position in accordance to specs (#295) e2cee9d6f · Andreas Weibye ·

1#[test]
2fn grid_absolute_align_self_sized_all() {
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            position: taffy::style::Position::Absolute,
10            align_self: Some(taffy::style::AlignSelf::Start),
11            size: taffy::geometry::Size {
12                width: taffy::style::Dimension::Points(20f32),
13                height: taffy::style::Dimension::Points(20f32),
14            },
15            ..Default::default()
16        })
17        .unwrap();
18    let node1 = taffy
19        .new_leaf(taffy::style::Style {
20            position: taffy::style::Position::Absolute,
21            align_self: Some(taffy::style::AlignSelf::Start),
22            size: taffy::geometry::Size {
23                width: taffy::style::Dimension::Points(60f32),
24                height: taffy::style::Dimension::Points(60f32),
25            },
26            ..Default::default()
27        })
28        .unwrap();
29    let node2 = taffy
30        .new_leaf(taffy::style::Style {
31            position: taffy::style::Position::Absolute,
32            align_self: Some(taffy::style::AlignSelf::End),
33            size: taffy::geometry::Size {
34                width: taffy::style::Dimension::Points(20f32),
35                height: taffy::style::Dimension::Points(20f32),
36            },
37            ..Default::default()
38        })
39        .unwrap();
40    let node3 = taffy
41        .new_leaf(taffy::style::Style {
42            position: taffy::style::Position::Absolute,
43            align_self: Some(taffy::style::AlignSelf::End),
44            size: taffy::geometry::Size {
45                width: taffy::style::Dimension::Points(60f32),
46                height: taffy::style::Dimension::Points(60f32),
47            },
48            ..Default::default()
49        })
50        .unwrap();
51    let node4 = taffy
52        .new_leaf(taffy::style::Style {
53            position: taffy::style::Position::Absolute,
54            align_self: Some(taffy::style::AlignSelf::Center),
55            size: taffy::geometry::Size {
56                width: taffy::style::Dimension::Points(20f32),
57                height: taffy::style::Dimension::Points(20f32),
58            },
59            ..Default::default()
60        })
61        .unwrap();
62    let node5 = taffy
63        .new_leaf(taffy::style::Style {
64            position: taffy::style::Position::Absolute,
65            align_self: Some(taffy::style::AlignSelf::Center),
66            size: taffy::geometry::Size {
67                width: taffy::style::Dimension::Points(60f32),
68                height: taffy::style::Dimension::Points(60f32),
69            },
70            ..Default::default()
71        })
72        .unwrap();
73    let node6 = taffy
74        .new_leaf(taffy::style::Style {
75            position: taffy::style::Position::Absolute,
76            align_self: Some(taffy::style::AlignSelf::Stretch),
77            size: taffy::geometry::Size {
78                width: taffy::style::Dimension::Points(20f32),
79                height: taffy::style::Dimension::Points(20f32),
80            },
81            ..Default::default()
82        })
83        .unwrap();
84    let node7 = taffy
85        .new_leaf(taffy::style::Style {
86            position: taffy::style::Position::Absolute,
87            align_self: Some(taffy::style::AlignSelf::Stretch),
88            size: taffy::geometry::Size {
89                width: taffy::style::Dimension::Points(60f32),
90                height: taffy::style::Dimension::Points(60f32),
91            },
92            ..Default::default()
93        })
94        .unwrap();
95    let node = taffy
96        .new_with_children(
97            taffy::style::Style {
98                display: taffy::style::Display::Grid,
99                grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
100                grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
101                size: taffy::geometry::Size {
102                    width: taffy::style::Dimension::Points(120f32),
103                    height: taffy::style::Dimension::Points(120f32),
104                },
105                ..Default::default()
106            },
107            &[node0, node1, node2, node3, node4, node5, node6, node7],
108        )
109        .unwrap();
110    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
111    println!("\nComputed tree:");
112    taffy::debug::print_tree(&taffy, node);
113    println!();
114    let Layout { size, location, .. } = taffy.layout(node).unwrap();
115    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.width);
116    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.height);
117    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
118    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
119    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
120    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
121    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
122    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
123    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
124    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
125    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.width);
126    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.height);
127    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
128    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
129    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
130    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.width);
131    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.height);
132    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
133    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, location.y);
134    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
135    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 60f32, size.width);
136    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 60f32, size.height);
137    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.x);
138    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 60f32, location.y);
139    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
140    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.width);
141    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.height);
142    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 0f32, location.x);
143    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 50f32, location.y);
144    let Layout { size, location, .. } = taffy.layout(node5).unwrap();
145    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node5.data(), 60f32, size.width);
146    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node5.data(), 60f32, size.height);
147    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node5.data(), 0f32, location.x);
148    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node5.data(), 30f32, location.y);
149    let Layout { size, location, .. } = taffy.layout(node6).unwrap();
150    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6.data(), 20f32, size.width);
151    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node6.data(), 20f32, size.height);
152    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6.data(), 0f32, location.x);
153    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node6.data(), 0f32, location.y);
154    let Layout { size, location, .. } = taffy.layout(node7).unwrap();
155    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node7.data(), 60f32, size.width);
156    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node7.data(), 60f32, size.height);
157    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node7.data(), 0f32, location.x);
158    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node7.data(), 0f32, location.y);
159}