gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 498HTML 254C 19JavaScript 81349 Sutichaykuna

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/wrapped_row_within_align_items_flex_end.rs Rust · 298 siq'ikuna · 11.8 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn wrapped_row_within_align_items_flex_end__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(150f32),
11                height: taffy::style::Dimension::Length(80f32),
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::Length(80f32),
20                height: taffy::style::Dimension::Length(80f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node0 = taffy
26        .new_with_children(
27            taffy::style::Style { flex_wrap: taffy::style::FlexWrap::Wrap, ..Default::default() },
28            &[node00, node01],
29        )
30        .unwrap();
31    let node = taffy
32        .new_with_children(
33            taffy::style::Style {
34                flex_direction: taffy::style::FlexDirection::Column,
35                align_items: Some(taffy::style::AlignItems::FlexEnd),
36                size: taffy::geometry::Size {
37                    width: taffy::style::Dimension::Length(200f32),
38                    height: taffy::style::Dimension::Length(200f32),
39                },
40                ..Default::default()
41            },
42            &[node0],
43        )
44        .unwrap();
45    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
46    println!("\nComputed tree:");
47    taffy.print_tree(node);
48    println!();
49    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
50    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
51    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
52    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
53    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
54    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
55    #[cfg(feature = "content_size")]
56    assert_eq!(
57        layout.scroll_width(),
58        0f32,
59        "scroll_width of node {:?}. Expected {}. Actual {}",
60        node,
61        0f32,
62        layout.scroll_width()
63    );
64    #[cfg(feature = "content_size")]
65    assert_eq!(
66        layout.scroll_height(),
67        0f32,
68        "scroll_height of node {:?}. Expected {}. Actual {}",
69        node,
70        0f32,
71        layout.scroll_height()
72    );
73    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
74    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
75    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
76    assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node0, 160f32, size.height);
77    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
78    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
79    #[cfg(feature = "content_size")]
80    assert_eq!(
81        layout.scroll_width(),
82        0f32,
83        "scroll_width of node {:?}. Expected {}. Actual {}",
84        node0,
85        0f32,
86        layout.scroll_width()
87    );
88    #[cfg(feature = "content_size")]
89    assert_eq!(
90        layout.scroll_height(),
91        0f32,
92        "scroll_height of node {:?}. Expected {}. Actual {}",
93        node0,
94        0f32,
95        layout.scroll_height()
96    );
97    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
98    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
99    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node00, 150f32, size.width);
100    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node00, 80f32, size.height);
101    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
102    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
103    #[cfg(feature = "content_size")]
104    assert_eq!(
105        layout.scroll_width(),
106        0f32,
107        "scroll_width of node {:?}. Expected {}. Actual {}",
108        node00,
109        0f32,
110        layout.scroll_width()
111    );
112    #[cfg(feature = "content_size")]
113    assert_eq!(
114        layout.scroll_height(),
115        0f32,
116        "scroll_height of node {:?}. Expected {}. Actual {}",
117        node00,
118        0f32,
119        layout.scroll_height()
120    );
121    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
122    let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
123    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node01, 80f32, size.width);
124    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node01, 80f32, size.height);
125    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
126    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node01, 80f32, location.y);
127    #[cfg(feature = "content_size")]
128    assert_eq!(
129        layout.scroll_width(),
130        0f32,
131        "scroll_width of node {:?}. Expected {}. Actual {}",
132        node01,
133        0f32,
134        layout.scroll_width()
135    );
136    #[cfg(feature = "content_size")]
137    assert_eq!(
138        layout.scroll_height(),
139        0f32,
140        "scroll_height of node {:?}. Expected {}. Actual {}",
141        node01,
142        0f32,
143        layout.scroll_height()
144    );
145}
146
147#[test]
148#[allow(non_snake_case)]
149fn wrapped_row_within_align_items_flex_end__content_box() {
150    #[allow(unused_imports)]
151    use taffy::{prelude::*, tree::Layout, TaffyTree};
152    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
153    let node00 = taffy
154        .new_leaf(taffy::style::Style {
155            box_sizing: taffy::style::BoxSizing::ContentBox,
156            size: taffy::geometry::Size {
157                width: taffy::style::Dimension::Length(150f32),
158                height: taffy::style::Dimension::Length(80f32),
159            },
160            ..Default::default()
161        })
162        .unwrap();
163    let node01 = taffy
164        .new_leaf(taffy::style::Style {
165            box_sizing: taffy::style::BoxSizing::ContentBox,
166            size: taffy::geometry::Size {
167                width: taffy::style::Dimension::Length(80f32),
168                height: taffy::style::Dimension::Length(80f32),
169            },
170            ..Default::default()
171        })
172        .unwrap();
173    let node0 = taffy
174        .new_with_children(
175            taffy::style::Style {
176                box_sizing: taffy::style::BoxSizing::ContentBox,
177                flex_wrap: taffy::style::FlexWrap::Wrap,
178                ..Default::default()
179            },
180            &[node00, node01],
181        )
182        .unwrap();
183    let node = taffy
184        .new_with_children(
185            taffy::style::Style {
186                box_sizing: taffy::style::BoxSizing::ContentBox,
187                flex_direction: taffy::style::FlexDirection::Column,
188                align_items: Some(taffy::style::AlignItems::FlexEnd),
189                size: taffy::geometry::Size {
190                    width: taffy::style::Dimension::Length(200f32),
191                    height: taffy::style::Dimension::Length(200f32),
192                },
193                ..Default::default()
194            },
195            &[node0],
196        )
197        .unwrap();
198    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
199    println!("\nComputed tree:");
200    taffy.print_tree(node);
201    println!();
202    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
203    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
204    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
205    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
206    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
207    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
208    #[cfg(feature = "content_size")]
209    assert_eq!(
210        layout.scroll_width(),
211        0f32,
212        "scroll_width of node {:?}. Expected {}. Actual {}",
213        node,
214        0f32,
215        layout.scroll_width()
216    );
217    #[cfg(feature = "content_size")]
218    assert_eq!(
219        layout.scroll_height(),
220        0f32,
221        "scroll_height of node {:?}. Expected {}. Actual {}",
222        node,
223        0f32,
224        layout.scroll_height()
225    );
226    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
227    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
228    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
229    assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node0, 160f32, size.height);
230    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
231    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
232    #[cfg(feature = "content_size")]
233    assert_eq!(
234        layout.scroll_width(),
235        0f32,
236        "scroll_width of node {:?}. Expected {}. Actual {}",
237        node0,
238        0f32,
239        layout.scroll_width()
240    );
241    #[cfg(feature = "content_size")]
242    assert_eq!(
243        layout.scroll_height(),
244        0f32,
245        "scroll_height of node {:?}. Expected {}. Actual {}",
246        node0,
247        0f32,
248        layout.scroll_height()
249    );
250    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
251    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
252    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node00, 150f32, size.width);
253    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node00, 80f32, size.height);
254    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
255    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
256    #[cfg(feature = "content_size")]
257    assert_eq!(
258        layout.scroll_width(),
259        0f32,
260        "scroll_width of node {:?}. Expected {}. Actual {}",
261        node00,
262        0f32,
263        layout.scroll_width()
264    );
265    #[cfg(feature = "content_size")]
266    assert_eq!(
267        layout.scroll_height(),
268        0f32,
269        "scroll_height of node {:?}. Expected {}. Actual {}",
270        node00,
271        0f32,
272        layout.scroll_height()
273    );
274    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
275    let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
276    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node01, 80f32, size.width);
277    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node01, 80f32, size.height);
278    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
279    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node01, 80f32, location.y);
280    #[cfg(feature = "content_size")]
281    assert_eq!(
282        layout.scroll_width(),
283        0f32,
284        "scroll_width of node {:?}. Expected {}. Actual {}",
285        node01,
286        0f32,
287        layout.scroll_width()
288    );
289    #[cfg(feature = "content_size")]
290    assert_eq!(
291        layout.scroll_height(),
292        0f32,
293        "scroll_height of node {:?}. Expected {}. Actual {}",
294        node01,
295        0f32,
296        layout.scroll_height()
297    );
298}