tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1077HTML 1008Markdown 12TOML 83209 Definitions

⎇ 859cc921b3adb8e3b184e6fc0cf0c40b6c5a625b tests/generated/grid_out_of_order_items.rs Rust · 114 lines · 8.0 KB History Who touched what raw

Grid/refactor coordinate handling (#301) 859cc921b · Nico Burns ·

1#[test]
2fn grid_out_of_order_items() {
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.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
9    let node2 = taffy
10        .new_leaf(taffy::style::Style {
11            grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
12            size: taffy::geometry::Size {
13                width: taffy::style::Dimension::Points(35f32),
14                height: taffy::style::Dimension::Points(35f32),
15            },
16            ..Default::default()
17        })
18        .unwrap();
19    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21    let node5 = taffy
22        .new_leaf(taffy::style::Style {
23            grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
24            grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
25            size: taffy::geometry::Size {
26                width: taffy::style::Dimension::Points(20f32),
27                height: taffy::style::Dimension::Points(20f32),
28            },
29            ..Default::default()
30        })
31        .unwrap();
32    let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
33    let node7 = taffy
34        .new_leaf(taffy::style::Style {
35            grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
36            size: taffy::geometry::Size {
37                width: taffy::style::Dimension::Points(10f32),
38                height: taffy::style::Dimension::Points(10f32),
39            },
40            ..Default::default()
41        })
42        .unwrap();
43    let node8 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
44    let node = taffy
45        .new_with_children(
46            taffy::style::Style {
47                display: taffy::style::Display::Grid,
48                grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
49                grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
50                grid_auto_flow: taffy::style::GridAutoFlow::RowDense,
51                size: taffy::geometry::Size {
52                    width: taffy::style::Dimension::Points(120f32),
53                    height: taffy::style::Dimension::Points(120f32),
54                },
55                ..Default::default()
56            },
57            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
58        )
59        .unwrap();
60    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
61    println!("\nComputed tree:");
62    taffy::debug::print_tree(&taffy, node);
63    println!();
64    let Layout { size, location, .. } = taffy.layout(node).unwrap();
65    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.width);
66    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.height);
67    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
68    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
69    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
70    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
71    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
72    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, location.x);
73    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
74    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
75    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.width);
76    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.height);
77    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
78    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y);
79    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
80    assert_eq!(size.width, 35f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 35f32, size.width);
81    assert_eq!(size.height, 35f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 35f32, size.height);
82    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
83    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 80f32, location.y);
84    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
85    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 40f32, size.width);
86    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 40f32, size.height);
87    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 40f32, location.x);
88    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 40f32, location.y);
89    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
90    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 40f32, size.width);
91    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 40f32, size.height);
92    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 80f32, location.x);
93    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 40f32, location.y);
94    let Layout { size, location, .. } = taffy.layout(node5).unwrap();
95    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5.data(), 20f32, size.width);
96    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5.data(), 20f32, size.height);
97    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node5.data(), 0f32, location.x);
98    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node5.data(), 0f32, location.y);
99    let Layout { size, location, .. } = taffy.layout(node6).unwrap();
100    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node6.data(), 40f32, size.width);
101    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6.data(), 40f32, size.height);
102    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node6.data(), 40f32, location.x);
103    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6.data(), 80f32, location.y);
104    let Layout { size, location, .. } = taffy.layout(node7).unwrap();
105    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node7.data(), 10f32, size.width);
106    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node7.data(), 10f32, size.height);
107    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7.data(), 40f32, location.x);
108    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node7.data(), 0f32, location.y);
109    let Layout { size, location, .. } = taffy.layout(node8).unwrap();
110    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8.data(), 40f32, size.width);
111    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8.data(), 40f32, size.height);
112    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node8.data(), 80f32, location.x);
113    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8.data(), 80f32, location.y);
114}