tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definiciones

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/bevy_issue_7976_4_level.rs Rust · 188 líneas · 9.1 KB Historia Quién tocó qué crudo

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn bevy_issue_7976_4_level__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node000 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node00 = taffy
9        .new_with_children(
10            taffy::style::Style {
11                size: taffy::geometry::Size {
12                    width: taffy::style::Dimension::from_percent(1f32),
13                    height: taffy::style::Dimension::from_percent(1f32),
14                },
15                padding: taffy::geometry::Rect {
16                    left: length(5f32),
17                    right: length(5f32),
18                    top: length(5f32),
19                    bottom: length(5f32),
20                },
21                ..Default::default()
22            },
23            &[node000],
24        )
25        .unwrap();
26    let node0 = taffy
27        .new_with_children(
28            taffy::style::Style {
29                min_size: taffy::geometry::Size {
30                    width: taffy::style::Dimension::from_length(40f32),
31                    height: taffy::style::Dimension::from_length(40f32),
32                },
33                margin: taffy::geometry::Rect {
34                    left: length(5f32),
35                    right: length(5f32),
36                    top: length(5f32),
37                    bottom: length(5f32),
38                },
39                padding: taffy::geometry::Rect {
40                    left: length(5f32),
41                    right: length(5f32),
42                    top: length(5f32),
43                    bottom: length(5f32),
44                },
45                ..Default::default()
46            },
47            &[node00],
48        )
49        .unwrap();
50    let node = taffy
51        .new_with_children(
52            taffy::style::Style {
53                align_content: Some(taffy::style::AlignContent::Start),
54                size: taffy::geometry::Size {
55                    width: taffy::style::Dimension::from_length(200f32),
56                    height: taffy::style::Dimension::from_length(200f32),
57                },
58                ..Default::default()
59            },
60            &[node0],
61        )
62        .unwrap();
63    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
64    println!("\nComputed tree:");
65    taffy.print_tree(node);
66    println!();
67    let layout = taffy.layout(node).unwrap();
68    let Layout { size, location, .. } = layout;
69    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
70    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
73    let layout = taffy.layout(node0).unwrap();
74    let Layout { size, location, .. } = layout;
75    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
76    assert_eq!(size.height, 190f32, "height of node {:?}. Expected {}. Actual {}", node0, 190f32, size.height);
77    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
78    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
79    let layout = taffy.layout(node00).unwrap();
80    let Layout { size, location, .. } = layout;
81    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node00, 30f32, size.width);
82    assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node00, 180f32, size.height);
83    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00, 5f32, location.x);
84    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00, 5f32, location.y);
85    let layout = taffy.layout(node000).unwrap();
86    let Layout { size, location, .. } = layout;
87    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node000, 0f32, size.width);
88    assert_eq!(size.height, 170f32, "height of node {:?}. Expected {}. Actual {}", node000, 170f32, size.height);
89    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node000, 5f32, location.x);
90    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node000, 5f32, location.y);
91}
92
93#[test]
94#[allow(non_snake_case)]
95fn bevy_issue_7976_4_level__content_box() {
96    #[allow(unused_imports)]
97    use taffy::{prelude::*, Layout};
98    let mut taffy = crate::new_test_tree();
99    let node000 = taffy
100        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
101        .unwrap();
102    let node00 = taffy
103        .new_with_children(
104            taffy::style::Style {
105                box_sizing: taffy::style::BoxSizing::ContentBox,
106                size: taffy::geometry::Size {
107                    width: taffy::style::Dimension::from_percent(1f32),
108                    height: taffy::style::Dimension::from_percent(1f32),
109                },
110                padding: taffy::geometry::Rect {
111                    left: length(5f32),
112                    right: length(5f32),
113                    top: length(5f32),
114                    bottom: length(5f32),
115                },
116                ..Default::default()
117            },
118            &[node000],
119        )
120        .unwrap();
121    let node0 = taffy
122        .new_with_children(
123            taffy::style::Style {
124                box_sizing: taffy::style::BoxSizing::ContentBox,
125                min_size: taffy::geometry::Size {
126                    width: taffy::style::Dimension::from_length(40f32),
127                    height: taffy::style::Dimension::from_length(40f32),
128                },
129                margin: taffy::geometry::Rect {
130                    left: length(5f32),
131                    right: length(5f32),
132                    top: length(5f32),
133                    bottom: length(5f32),
134                },
135                padding: taffy::geometry::Rect {
136                    left: length(5f32),
137                    right: length(5f32),
138                    top: length(5f32),
139                    bottom: length(5f32),
140                },
141                ..Default::default()
142            },
143            &[node00],
144        )
145        .unwrap();
146    let node = taffy
147        .new_with_children(
148            taffy::style::Style {
149                box_sizing: taffy::style::BoxSizing::ContentBox,
150                align_content: Some(taffy::style::AlignContent::Start),
151                size: taffy::geometry::Size {
152                    width: taffy::style::Dimension::from_length(200f32),
153                    height: taffy::style::Dimension::from_length(200f32),
154                },
155                ..Default::default()
156            },
157            &[node0],
158        )
159        .unwrap();
160    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
161    println!("\nComputed tree:");
162    taffy.print_tree(node);
163    println!();
164    let layout = taffy.layout(node).unwrap();
165    let Layout { size, location, .. } = layout;
166    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
167    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
168    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
169    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
170    let layout = taffy.layout(node0).unwrap();
171    let Layout { size, location, .. } = layout;
172    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
173    assert_eq!(size.height, 190f32, "height of node {:?}. Expected {}. Actual {}", node0, 190f32, size.height);
174    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
175    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
176    let layout = taffy.layout(node00).unwrap();
177    let Layout { size, location, .. } = layout;
178    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
179    assert_eq!(size.height, 190f32, "height of node {:?}. Expected {}. Actual {}", node00, 190f32, size.height);
180    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00, 5f32, location.x);
181    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00, 5f32, location.y);
182    let layout = taffy.layout(node000).unwrap();
183    let Layout { size, location, .. } = layout;
184    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node000, 0f32, size.width);
185    assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node000, 180f32, size.height);
186    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node000, 5f32, location.x);
187    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node000, 5f32, location.y);
188}