tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Definitions

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