gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definitions

⎇ 01babab32d8138f3c3fa05095fb6c65fca0d3967 tests/generated/wrapped_column_max_height.rs Rust · 82 lines · 4.5 KB History Who touched what raw

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

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