tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 859HTML 402Markdown 10TOML 52492 Definitions

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/align_content_flex_start.rs Rust · 219 lines · 11.4 KB History Who touched what raw

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

1#[test]
2#[allow(non_snake_case)]
3fn align_content_flex_start__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = 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(10f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node1 = 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(10f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node2 = 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(10f32),
30            },
31            ..Default::default()
32        })
33        .unwrap();
34    let node3 = 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(10f32),
39            },
40            ..Default::default()
41        })
42        .unwrap();
43    let node4 = taffy
44        .new_leaf(taffy::style::Style {
45            size: taffy::geometry::Size {
46                width: taffy::style::Dimension::from_length(50f32),
47                height: taffy::style::Dimension::from_length(10f32),
48            },
49            ..Default::default()
50        })
51        .unwrap();
52    let node = taffy
53        .new_with_children(
54            taffy::style::Style {
55                flex_wrap: taffy::style::FlexWrap::Wrap,
56                align_content: Some(taffy::style::AlignContent::FlexStart),
57                size: taffy::geometry::Size {
58                    width: taffy::style::Dimension::from_length(130f32),
59                    height: taffy::style::Dimension::from_length(100f32),
60                },
61                ..Default::default()
62            },
63            &[node0, node1, node2, node3, node4],
64        )
65        .unwrap();
66    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
67    println!("\nComputed tree:");
68    taffy.print_tree(node);
69    println!();
70    let layout = taffy.layout(node).unwrap();
71    let Layout { size, location, .. } = layout;
72    assert_eq!(size.width, 130f32, "width of node {:?}. Expected {}. Actual {}", node, 130f32, size.width);
73    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
74    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
76    let layout = taffy.layout(node0).unwrap();
77    let Layout { size, location, .. } = layout;
78    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
79    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
82    let layout = taffy.layout(node1).unwrap();
83    let Layout { size, location, .. } = layout;
84    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
85    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
86    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
87    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
88    let layout = taffy.layout(node2).unwrap();
89    let Layout { size, location, .. } = layout;
90    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
91    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
92    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
93    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2, 10f32, location.y);
94    let layout = taffy.layout(node3).unwrap();
95    let Layout { size, location, .. } = layout;
96    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
97    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
98    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
99    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node3, 10f32, location.y);
100    let layout = taffy.layout(node4).unwrap();
101    let Layout { size, location, .. } = layout;
102    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
103    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
104    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
105    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node4, 20f32, location.y);
106}
107
108#[test]
109#[allow(non_snake_case)]
110fn align_content_flex_start__content_box() {
111    #[allow(unused_imports)]
112    use taffy::{prelude::*, Layout};
113    let mut taffy = crate::new_test_tree();
114    let node0 = taffy
115        .new_leaf(taffy::style::Style {
116            box_sizing: taffy::style::BoxSizing::ContentBox,
117            size: taffy::geometry::Size {
118                width: taffy::style::Dimension::from_length(50f32),
119                height: taffy::style::Dimension::from_length(10f32),
120            },
121            ..Default::default()
122        })
123        .unwrap();
124    let node1 = taffy
125        .new_leaf(taffy::style::Style {
126            box_sizing: taffy::style::BoxSizing::ContentBox,
127            size: taffy::geometry::Size {
128                width: taffy::style::Dimension::from_length(50f32),
129                height: taffy::style::Dimension::from_length(10f32),
130            },
131            ..Default::default()
132        })
133        .unwrap();
134    let node2 = taffy
135        .new_leaf(taffy::style::Style {
136            box_sizing: taffy::style::BoxSizing::ContentBox,
137            size: taffy::geometry::Size {
138                width: taffy::style::Dimension::from_length(50f32),
139                height: taffy::style::Dimension::from_length(10f32),
140            },
141            ..Default::default()
142        })
143        .unwrap();
144    let node3 = taffy
145        .new_leaf(taffy::style::Style {
146            box_sizing: taffy::style::BoxSizing::ContentBox,
147            size: taffy::geometry::Size {
148                width: taffy::style::Dimension::from_length(50f32),
149                height: taffy::style::Dimension::from_length(10f32),
150            },
151            ..Default::default()
152        })
153        .unwrap();
154    let node4 = taffy
155        .new_leaf(taffy::style::Style {
156            box_sizing: taffy::style::BoxSizing::ContentBox,
157            size: taffy::geometry::Size {
158                width: taffy::style::Dimension::from_length(50f32),
159                height: taffy::style::Dimension::from_length(10f32),
160            },
161            ..Default::default()
162        })
163        .unwrap();
164    let node = taffy
165        .new_with_children(
166            taffy::style::Style {
167                box_sizing: taffy::style::BoxSizing::ContentBox,
168                flex_wrap: taffy::style::FlexWrap::Wrap,
169                align_content: Some(taffy::style::AlignContent::FlexStart),
170                size: taffy::geometry::Size {
171                    width: taffy::style::Dimension::from_length(130f32),
172                    height: taffy::style::Dimension::from_length(100f32),
173                },
174                ..Default::default()
175            },
176            &[node0, node1, node2, node3, node4],
177        )
178        .unwrap();
179    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
180    println!("\nComputed tree:");
181    taffy.print_tree(node);
182    println!();
183    let layout = taffy.layout(node).unwrap();
184    let Layout { size, location, .. } = layout;
185    assert_eq!(size.width, 130f32, "width of node {:?}. Expected {}. Actual {}", node, 130f32, size.width);
186    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
187    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
188    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
189    let layout = taffy.layout(node0).unwrap();
190    let Layout { size, location, .. } = layout;
191    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
192    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
193    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
194    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
195    let layout = taffy.layout(node1).unwrap();
196    let Layout { size, location, .. } = layout;
197    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
198    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
199    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
200    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
201    let layout = taffy.layout(node2).unwrap();
202    let Layout { size, location, .. } = layout;
203    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
204    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
205    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
206    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2, 10f32, location.y);
207    let layout = taffy.layout(node3).unwrap();
208    let Layout { size, location, .. } = layout;
209    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
210    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
211    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
212    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node3, 10f32, location.y);
213    let layout = taffy.layout(node4).unwrap();
214    let Layout { size, location, .. } = layout;
215    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
216    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
217    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
218    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node4, 20f32, location.y);
219}