gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94524 Sutichaykuna

⎇ 01babab32d8138f3c3fa05095fb6c65fca0d3967 tests/generated/wrap_row_align_items_flex_end.rs Rust · 83 siq'ikuna · 4.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn wrap_row_align_items_flex_end() {
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 {
10                width: taffy::style::Dimension::Points(30f32),
11                height: taffy::style::Dimension::Points(10f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node1 = taffy
17        .new_leaf(taffy::style::Style {
18            size: taffy::geometry::Size {
19                width: taffy::style::Dimension::Points(30f32),
20                height: taffy::style::Dimension::Points(20f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node2 = taffy
26        .new_leaf(taffy::style::Style {
27            size: taffy::geometry::Size {
28                width: taffy::style::Dimension::Points(30f32),
29                height: taffy::style::Dimension::Points(30f32),
30            },
31            ..Default::default()
32        })
33        .unwrap();
34    let node3 = taffy
35        .new_leaf(taffy::style::Style {
36            size: taffy::geometry::Size {
37                width: taffy::style::Dimension::Points(30f32),
38                height: taffy::style::Dimension::Points(30f32),
39            },
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::End),
48                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: auto() },
49                ..Default::default()
50            },
51            &[node0, node1, node2, node3],
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, 60f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 60f32, 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, 30f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.width);
65    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.height);
66    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
67    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, location.y);
68    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
69    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, size.width);
70    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
71    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, location.x);
72    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 10f32, location.y);
73    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
74    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 30f32, size.width);
75    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 30f32, size.height);
76    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 60f32, location.x);
77    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
78    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
79    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, size.width);
80    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.x);
82    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, location.y);
83}