⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/flex/bevy_issue_8082_percent.rs
History
Who touched what
raw
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn bevy_issue_8082_percent__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node00 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::from_length(50f32),
11 height: taffy::style::Dimension::from_length(50f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node01 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::from_length(50f32),
20 height: taffy::style::Dimension::from_length(50f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node02 = taffy
26 .new_leaf(taffy::style::Style {
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::from_length(50f32),
29 height: taffy::style::Dimension::from_length(50f32),
30 },
31 ..Default::default()
32 })
33 .unwrap();
34 let node03 = taffy
35 .new_leaf(taffy::style::Style {
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::from_length(50f32),
38 height: taffy::style::Dimension::from_length(50f32),
39 },
40 ..Default::default()
41 })
42 .unwrap();
43 let node0 = taffy
44 .new_with_children(
45 taffy::style::Style {
46 flex_wrap: taffy::style::FlexWrap::Wrap,
47 align_items: Some(taffy::style::AlignItems::FlexStart),
48 align_content: Some(taffy::style::AlignContent::Center),
49 justify_content: Some(taffy::style::JustifyContent::Center),
50 size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.5f32), height: auto() },
51 ..Default::default()
52 },
53 &[node00, node01, node02, node03],
54 )
55 .unwrap();
56 let node = taffy
57 .new_with_children(
58 taffy::style::Style {
59 flex_direction: taffy::style::FlexDirection::Column,
60 align_items: Some(taffy::style::AlignItems::Stretch),
61 align_content: Some(taffy::style::AlignContent::Center),
62 justify_content: Some(taffy::style::JustifyContent::FlexStart),
63 size: taffy::geometry::Size {
64 width: taffy::style::Dimension::from_length(200f32),
65 height: taffy::style::Dimension::from_length(400f32),
66 },
67 ..Default::default()
68 },
69 &[node0],
70 )
71 .unwrap();
72 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
73 println!("\nComputed tree:");
74 taffy.print_tree(node);
75 println!();
76 let layout = taffy.layout(node).unwrap();
77 let Layout { size, location, .. } = layout;
78 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
79 assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node, 400f32, size.height);
80 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
81 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
82 let layout = taffy.layout(node0).unwrap();
83 let Layout { size, location, .. } = layout;
84 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
85 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
86 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
87 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
88 let layout = taffy.layout(node00).unwrap();
89 let Layout { size, location, .. } = layout;
90 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
91 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
92 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
93 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
94 let layout = taffy.layout(node01).unwrap();
95 let Layout { size, location, .. } = layout;
96 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
97 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node01, 50f32, size.height);
98 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node01, 50f32, location.x);
99 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
100 let layout = taffy.layout(node02).unwrap();
101 let Layout { size, location, .. } = layout;
102 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node02, 50f32, size.width);
103 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node02, 50f32, size.height);
104 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
105 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node02, 50f32, location.y);
106 let layout = taffy.layout(node03).unwrap();
107 let Layout { size, location, .. } = layout;
108 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node03, 50f32, size.width);
109 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node03, 50f32, size.height);
110 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node03, 50f32, location.x);
111 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node03, 50f32, location.y);
112}
113
114#[test]
115#[allow(non_snake_case)]
116fn bevy_issue_8082_percent__content_box() {
117 #[allow(unused_imports)]
118 use taffy::{prelude::*, Layout};
119 let mut taffy = crate::new_test_tree();
120 let node00 = taffy
121 .new_leaf(taffy::style::Style {
122 box_sizing: taffy::style::BoxSizing::ContentBox,
123 size: taffy::geometry::Size {
124 width: taffy::style::Dimension::from_length(50f32),
125 height: taffy::style::Dimension::from_length(50f32),
126 },
127 ..Default::default()
128 })
129 .unwrap();
130 let node01 = taffy
131 .new_leaf(taffy::style::Style {
132 box_sizing: taffy::style::BoxSizing::ContentBox,
133 size: taffy::geometry::Size {
134 width: taffy::style::Dimension::from_length(50f32),
135 height: taffy::style::Dimension::from_length(50f32),
136 },
137 ..Default::default()
138 })
139 .unwrap();
140 let node02 = taffy
141 .new_leaf(taffy::style::Style {
142 box_sizing: taffy::style::BoxSizing::ContentBox,
143 size: taffy::geometry::Size {
144 width: taffy::style::Dimension::from_length(50f32),
145 height: taffy::style::Dimension::from_length(50f32),
146 },
147 ..Default::default()
148 })
149 .unwrap();
150 let node03 = taffy
151 .new_leaf(taffy::style::Style {
152 box_sizing: taffy::style::BoxSizing::ContentBox,
153 size: taffy::geometry::Size {
154 width: taffy::style::Dimension::from_length(50f32),
155 height: taffy::style::Dimension::from_length(50f32),
156 },
157 ..Default::default()
158 })
159 .unwrap();
160 let node0 = taffy
161 .new_with_children(
162 taffy::style::Style {
163 box_sizing: taffy::style::BoxSizing::ContentBox,
164 flex_wrap: taffy::style::FlexWrap::Wrap,
165 align_items: Some(taffy::style::AlignItems::FlexStart),
166 align_content: Some(taffy::style::AlignContent::Center),
167 justify_content: Some(taffy::style::JustifyContent::Center),
168 size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(0.5f32), height: auto() },
169 ..Default::default()
170 },
171 &[node00, node01, node02, node03],
172 )
173 .unwrap();
174 let node = taffy
175 .new_with_children(
176 taffy::style::Style {
177 box_sizing: taffy::style::BoxSizing::ContentBox,
178 flex_direction: taffy::style::FlexDirection::Column,
179 align_items: Some(taffy::style::AlignItems::Stretch),
180 align_content: Some(taffy::style::AlignContent::Center),
181 justify_content: Some(taffy::style::JustifyContent::FlexStart),
182 size: taffy::geometry::Size {
183 width: taffy::style::Dimension::from_length(200f32),
184 height: taffy::style::Dimension::from_length(400f32),
185 },
186 ..Default::default()
187 },
188 &[node0],
189 )
190 .unwrap();
191 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
192 println!("\nComputed tree:");
193 taffy.print_tree(node);
194 println!();
195 let layout = taffy.layout(node).unwrap();
196 let Layout { size, location, .. } = layout;
197 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
198 assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node, 400f32, size.height);
199 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
200 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
201 let layout = taffy.layout(node0).unwrap();
202 let Layout { size, location, .. } = layout;
203 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
204 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
205 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
206 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
207 let layout = taffy.layout(node00).unwrap();
208 let Layout { size, location, .. } = layout;
209 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
210 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
211 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
212 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
213 let layout = taffy.layout(node01).unwrap();
214 let Layout { size, location, .. } = layout;
215 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
216 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node01, 50f32, size.height);
217 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node01, 50f32, location.x);
218 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
219 let layout = taffy.layout(node02).unwrap();
220 let Layout { size, location, .. } = layout;
221 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node02, 50f32, size.width);
222 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node02, 50f32, size.height);
223 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
224 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node02, 50f32, location.y);
225 let layout = taffy.layout(node03).unwrap();
226 let Layout { size, location, .. } = layout;
227 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node03, 50f32, size.width);
228 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node03, 50f32, size.height);
229 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node03, 50f32, location.x);
230 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node03, 50f32, location.y);
231}