tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1100HTML 1031Markdown 12TOML 84455 Definitions

⎇ 0.3.x tests/generated/wrapped_column_max_height_flex.rs Rust · 88 lines · 4.7 KB History Who touched what raw

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

1#[test]
2fn wrapped_column_max_height_flex() {
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            flex_grow: 1f32,
10            flex_shrink: 1f32,
11            flex_basis: taffy::style::Dimension::Percent(0f32),
12            size: taffy::geometry::Size {
13                width: taffy::style::Dimension::Points(100f32),
14                height: taffy::style::Dimension::Points(500f32),
15            },
16            max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(200f32) },
17            ..Default::default()
18        })
19        .unwrap();
20    let node1 = taffy
21        .new_leaf(taffy::style::Style {
22            flex_grow: 1f32,
23            flex_shrink: 1f32,
24            flex_basis: taffy::style::Dimension::Percent(0f32),
25            size: taffy::geometry::Size {
26                width: taffy::style::Dimension::Points(200f32),
27                height: taffy::style::Dimension::Points(200f32),
28            },
29            margin: taffy::geometry::Rect {
30                left: taffy::style::LengthPercentageAuto::Points(20f32),
31                right: taffy::style::LengthPercentageAuto::Points(20f32),
32                top: taffy::style::LengthPercentageAuto::Points(20f32),
33                bottom: taffy::style::LengthPercentageAuto::Points(20f32),
34            },
35            ..Default::default()
36        })
37        .unwrap();
38    let node2 = taffy
39        .new_leaf(taffy::style::Style {
40            size: taffy::geometry::Size {
41                width: taffy::style::Dimension::Points(100f32),
42                height: taffy::style::Dimension::Points(100f32),
43            },
44            ..Default::default()
45        })
46        .unwrap();
47    let node = taffy
48        .new_with_children(
49            taffy::style::Style {
50                flex_direction: taffy::style::FlexDirection::Column,
51                flex_wrap: taffy::style::FlexWrap::Wrap,
52                align_items: Some(taffy::style::AlignItems::Center),
53                align_content: Some(taffy::style::AlignContent::Center),
54                justify_content: Some(taffy::style::JustifyContent::Center),
55                size: taffy::geometry::Size {
56                    width: taffy::style::Dimension::Points(700f32),
57                    height: taffy::style::Dimension::Points(500f32),
58                },
59                ..Default::default()
60            },
61            &[node0, node1, node2],
62        )
63        .unwrap();
64    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
65    println!("\nComputed tree:");
66    taffy::debug::print_tree(&taffy, node);
67    println!();
68    let Layout { size, location, .. } = taffy.layout(node).unwrap();
69    assert_eq!(size.width, 700f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 700f32, size.width);
70    assert_eq!(size.height, 500f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 500f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
73    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
74    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
75    assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 180f32, size.height);
76    assert_eq!(location.x, 300f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 300f32, location.x);
77    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
78    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
79    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 200f32, size.width);
80    assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 180f32, size.height);
81    assert_eq!(location.x, 250f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 250f32, location.x);
82    assert_eq!(location.y, 200f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 200f32, location.y);
83    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
84    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, size.width);
85    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, size.height);
86    assert_eq!(location.x, 300f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 300f32, location.x);
87    assert_eq!(location.y, 400f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 400f32, location.y);
88}