tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

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