gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 496HTML 245JavaScript 8CSS 61214 Definitions

⎇ 0.2.x tests/generated/wrapped_column_max_height.rs Rust · 89 lines · 3.7 KB History Who touched what raw

Rename Rect field start->left end->right (#257) ca514f6c8 · Nico Burns ·

1#[test]
2fn wrapped_column_max_height() {
3    let mut taffy = taffy::Taffy::new();
4    let node0 = taffy
5        .new_with_children(
6            taffy::style::Style {
7                size: taffy::geometry::Size {
8                    width: taffy::style::Dimension::Points(100f32),
9                    height: taffy::style::Dimension::Points(500f32),
10                    ..Default::default()
11                },
12                max_size: taffy::geometry::Size {
13                    height: taffy::style::Dimension::Points(200f32),
14                    ..Default::default()
15                },
16                ..Default::default()
17            },
18            &[],
19        )
20        .unwrap();
21    let node1 = taffy
22        .new_with_children(
23            taffy::style::Style {
24                size: taffy::geometry::Size {
25                    width: taffy::style::Dimension::Points(200f32),
26                    height: taffy::style::Dimension::Points(200f32),
27                    ..Default::default()
28                },
29                margin: taffy::geometry::Rect {
30                    left: taffy::style::Dimension::Points(20f32),
31                    right: taffy::style::Dimension::Points(20f32),
32                    top: taffy::style::Dimension::Points(20f32),
33                    bottom: taffy::style::Dimension::Points(20f32),
34                    ..Default::default()
35                },
36                ..Default::default()
37            },
38            &[],
39        )
40        .unwrap();
41    let node2 = taffy
42        .new_with_children(
43            taffy::style::Style {
44                size: taffy::geometry::Size {
45                    width: taffy::style::Dimension::Points(100f32),
46                    height: taffy::style::Dimension::Points(100f32),
47                    ..Default::default()
48                },
49                ..Default::default()
50            },
51            &[],
52        )
53        .unwrap();
54    let node = taffy
55        .new_with_children(
56            taffy::style::Style {
57                flex_direction: taffy::style::FlexDirection::Column,
58                flex_wrap: taffy::style::FlexWrap::Wrap,
59                align_items: taffy::style::AlignItems::Center,
60                align_content: taffy::style::AlignContent::Center,
61                justify_content: taffy::style::JustifyContent::Center,
62                size: taffy::geometry::Size {
63                    width: taffy::style::Dimension::Points(700f32),
64                    height: taffy::style::Dimension::Points(500f32),
65                    ..Default::default()
66                },
67                ..Default::default()
68            },
69            &[node0, node1, node2],
70        )
71        .unwrap();
72    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
73    assert_eq!(taffy.layout(node).unwrap().size.width, 700f32);
74    assert_eq!(taffy.layout(node).unwrap().size.height, 500f32);
75    assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
76    assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
77    assert_eq!(taffy.layout(node0).unwrap().size.width, 100f32);
78    assert_eq!(taffy.layout(node0).unwrap().size.height, 200f32);
79    assert_eq!(taffy.layout(node0).unwrap().location.x, 250f32);
80    assert_eq!(taffy.layout(node0).unwrap().location.y, 30f32);
81    assert_eq!(taffy.layout(node1).unwrap().size.width, 200f32);
82    assert_eq!(taffy.layout(node1).unwrap().size.height, 200f32);
83    assert_eq!(taffy.layout(node1).unwrap().location.x, 200f32);
84    assert_eq!(taffy.layout(node1).unwrap().location.y, 250f32);
85    assert_eq!(taffy.layout(node2).unwrap().size.width, 100f32);
86    assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32);
87    assert_eq!(taffy.layout(node2).unwrap().location.x, 420f32);
88    assert_eq!(taffy.layout(node2).unwrap().location.y, 200f32);
89}