tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Definitions

⎇ 859cc921b3adb8e3b184e6fc0cf0c40b6c5a625b tests/generated/gap_row_gap_align_items_stretch.rs Rust · 101 lines · 6.1 KB History Who touched what raw

Better assert messages (#290) 2b7d63a03 · Nico Burns ·

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