gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 979HTML 924Markdown 12TOML 82994 Definiciones

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/bevy_issue_8082.rs Rust · 128 líneas · 6.9 KB Historia Quién tocó qué crudo

Rename `Points`/`points` to `Length`/`length` in many APIs (#459) 55abeaf2e · Simon Sapin ·

1#[test]
2fn bevy_issue_8082() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(50f32),
10                height: taffy::style::Dimension::Length(50f32),
11            },
12            margin: taffy::geometry::Rect {
13                left: taffy::style::LengthPercentageAuto::Length(10f32),
14                right: taffy::style::LengthPercentageAuto::Length(10f32),
15                top: taffy::style::LengthPercentageAuto::Length(10f32),
16                bottom: taffy::style::LengthPercentageAuto::Length(10f32),
17            },
18            ..Default::default()
19        })
20        .unwrap();
21    let node01 = taffy
22        .new_leaf(taffy::style::Style {
23            size: taffy::geometry::Size {
24                width: taffy::style::Dimension::Length(50f32),
25                height: taffy::style::Dimension::Length(50f32),
26            },
27            margin: taffy::geometry::Rect {
28                left: taffy::style::LengthPercentageAuto::Length(10f32),
29                right: taffy::style::LengthPercentageAuto::Length(10f32),
30                top: taffy::style::LengthPercentageAuto::Length(10f32),
31                bottom: taffy::style::LengthPercentageAuto::Length(10f32),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node02 = taffy
37        .new_leaf(taffy::style::Style {
38            size: taffy::geometry::Size {
39                width: taffy::style::Dimension::Length(50f32),
40                height: taffy::style::Dimension::Length(50f32),
41            },
42            margin: taffy::geometry::Rect {
43                left: taffy::style::LengthPercentageAuto::Length(10f32),
44                right: taffy::style::LengthPercentageAuto::Length(10f32),
45                top: taffy::style::LengthPercentageAuto::Length(10f32),
46                bottom: taffy::style::LengthPercentageAuto::Length(10f32),
47            },
48            ..Default::default()
49        })
50        .unwrap();
51    let node03 = taffy
52        .new_leaf(taffy::style::Style {
53            size: taffy::geometry::Size {
54                width: taffy::style::Dimension::Length(50f32),
55                height: taffy::style::Dimension::Length(50f32),
56            },
57            margin: taffy::geometry::Rect {
58                left: taffy::style::LengthPercentageAuto::Length(10f32),
59                right: taffy::style::LengthPercentageAuto::Length(10f32),
60                top: taffy::style::LengthPercentageAuto::Length(10f32),
61                bottom: taffy::style::LengthPercentageAuto::Length(10f32),
62            },
63            ..Default::default()
64        })
65        .unwrap();
66    let node0 = taffy
67        .new_with_children(
68            taffy::style::Style {
69                flex_wrap: taffy::style::FlexWrap::Wrap,
70                align_items: Some(taffy::style::AlignItems::FlexStart),
71                align_content: Some(taffy::style::AlignContent::Center),
72                justify_content: Some(taffy::style::JustifyContent::Center),
73                ..Default::default()
74            },
75            &[node00, node01, node02, node03],
76        )
77        .unwrap();
78    let node = taffy
79        .new_with_children(
80            taffy::style::Style {
81                flex_direction: taffy::style::FlexDirection::Column,
82                align_items: Some(taffy::style::AlignItems::Stretch),
83                align_content: Some(taffy::style::AlignContent::Center),
84                justify_content: Some(taffy::style::JustifyContent::FlexStart),
85                size: taffy::geometry::Size {
86                    width: taffy::style::Dimension::Length(200f32),
87                    height: taffy::style::Dimension::Length(400f32),
88                },
89                ..Default::default()
90            },
91            &[node0],
92        )
93        .unwrap();
94    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
95    println!("\nComputed tree:");
96    taffy::util::print_tree(&taffy, node);
97    println!();
98    let Layout { size, location, .. } = taffy.layout(node).unwrap();
99    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
100    assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node, 400f32, size.height);
101    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
102    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
103    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
104    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
105    assert_eq!(size.height, 140f32, "height of node {:?}. Expected {}. Actual {}", node0, 140f32, size.height);
106    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
107    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
108    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
109    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
110    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
111    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node00, 40f32, location.x);
112    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node00, 10f32, location.y);
113    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
114    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
115    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node01, 50f32, size.height);
116    assert_eq!(location.x, 110f32, "x of node {:?}. Expected {}. Actual {}", node01, 110f32, location.x);
117    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node01, 10f32, location.y);
118    let Layout { size, location, .. } = taffy.layout(node02).unwrap();
119    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node02, 50f32, size.width);
120    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node02, 50f32, size.height);
121    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node02, 40f32, location.x);
122    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node02, 80f32, location.y);
123    let Layout { size, location, .. } = taffy.layout(node03).unwrap();
124    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node03, 50f32, size.width);
125    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node03, 50f32, size.height);
126    assert_eq!(location.x, 110f32, "x of node {:?}. Expected {}. Actual {}", node03, 110f32, location.x);
127    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node03, 80f32, location.y);
128}