tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1082HTML 1014Markdown 12TOML 83222 Definiciones

⎇ direction-floats tests/generated/flex/align_content_stretch_row_with_margin.rs Rust · 213 líneas · 11.4 KB Historia Quién tocó qué crudo

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

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