gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1117HTML 1044Markdown 12TOML 94797 Definiciones

⎇ 0.5.x tests/generated/flex/align_content_space_around_wrapped.rs Rust · 246 líneas · 9.8 KB Historia Quién tocó qué crudo

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn align_content_space_around_wrapped() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(50f32),
10                height: taffy::style::Dimension::Length(10f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node1 = taffy
16        .new_leaf(taffy::style::Style {
17            size: taffy::geometry::Size {
18                width: taffy::style::Dimension::Length(50f32),
19                height: taffy::style::Dimension::Length(10f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node2 = taffy
25        .new_leaf(taffy::style::Style {
26            size: taffy::geometry::Size {
27                width: taffy::style::Dimension::Length(50f32),
28                height: taffy::style::Dimension::Length(10f32),
29            },
30            ..Default::default()
31        })
32        .unwrap();
33    let node3 = taffy
34        .new_leaf(taffy::style::Style {
35            size: taffy::geometry::Size {
36                width: taffy::style::Dimension::Length(50f32),
37                height: taffy::style::Dimension::Length(10f32),
38            },
39            ..Default::default()
40        })
41        .unwrap();
42    let node4 = taffy
43        .new_leaf(taffy::style::Style {
44            size: taffy::geometry::Size {
45                width: taffy::style::Dimension::Length(50f32),
46                height: taffy::style::Dimension::Length(10f32),
47            },
48            ..Default::default()
49        })
50        .unwrap();
51    let node5 = taffy
52        .new_leaf(taffy::style::Style {
53            size: taffy::geometry::Size {
54                width: taffy::style::Dimension::Length(50f32),
55                height: taffy::style::Dimension::Length(10f32),
56            },
57            ..Default::default()
58        })
59        .unwrap();
60    let node = taffy
61        .new_with_children(
62            taffy::style::Style {
63                flex_wrap: taffy::style::FlexWrap::Wrap,
64                align_content: Some(taffy::style::AlignContent::SpaceAround),
65                size: taffy::geometry::Size {
66                    width: taffy::style::Dimension::Length(100f32),
67                    height: taffy::style::Dimension::Length(100f32),
68                },
69                ..Default::default()
70            },
71            &[node0, node1, node2, node3, node4, node5],
72        )
73        .unwrap();
74    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
75    println!("\nComputed tree:");
76    taffy.print_tree(node);
77    println!();
78    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
79    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
80    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
81    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
82    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
83    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
84    #[cfg(feature = "content_size")]
85    assert_eq!(
86        layout.scroll_width(),
87        0f32,
88        "scroll_width of node {:?}. Expected {}. Actual {}",
89        node,
90        0f32,
91        layout.scroll_width()
92    );
93    #[cfg(feature = "content_size")]
94    assert_eq!(
95        layout.scroll_height(),
96        0f32,
97        "scroll_height of node {:?}. Expected {}. Actual {}",
98        node,
99        0f32,
100        layout.scroll_height()
101    );
102    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
103    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
104    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
105    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
106    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
107    assert_eq!(location.y, 12f32, "y of node {:?}. Expected {}. Actual {}", node0, 12f32, location.y);
108    #[cfg(feature = "content_size")]
109    assert_eq!(
110        layout.scroll_width(),
111        0f32,
112        "scroll_width of node {:?}. Expected {}. Actual {}",
113        node0,
114        0f32,
115        layout.scroll_width()
116    );
117    #[cfg(feature = "content_size")]
118    assert_eq!(
119        layout.scroll_height(),
120        0f32,
121        "scroll_height of node {:?}. Expected {}. Actual {}",
122        node0,
123        0f32,
124        layout.scroll_height()
125    );
126    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
127    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
128    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
129    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
130    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
131    assert_eq!(location.y, 12f32, "y of node {:?}. Expected {}. Actual {}", node1, 12f32, location.y);
132    #[cfg(feature = "content_size")]
133    assert_eq!(
134        layout.scroll_width(),
135        0f32,
136        "scroll_width of node {:?}. Expected {}. Actual {}",
137        node1,
138        0f32,
139        layout.scroll_width()
140    );
141    #[cfg(feature = "content_size")]
142    assert_eq!(
143        layout.scroll_height(),
144        0f32,
145        "scroll_height of node {:?}. Expected {}. Actual {}",
146        node1,
147        0f32,
148        layout.scroll_height()
149    );
150    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
151    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
152    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
153    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
154    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
155    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node2, 45f32, location.y);
156    #[cfg(feature = "content_size")]
157    assert_eq!(
158        layout.scroll_width(),
159        0f32,
160        "scroll_width of node {:?}. Expected {}. Actual {}",
161        node2,
162        0f32,
163        layout.scroll_width()
164    );
165    #[cfg(feature = "content_size")]
166    assert_eq!(
167        layout.scroll_height(),
168        0f32,
169        "scroll_height of node {:?}. Expected {}. Actual {}",
170        node2,
171        0f32,
172        layout.scroll_height()
173    );
174    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
175    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
176    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
177    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
178    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
179    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node3, 45f32, location.y);
180    #[cfg(feature = "content_size")]
181    assert_eq!(
182        layout.scroll_width(),
183        0f32,
184        "scroll_width of node {:?}. Expected {}. Actual {}",
185        node3,
186        0f32,
187        layout.scroll_width()
188    );
189    #[cfg(feature = "content_size")]
190    assert_eq!(
191        layout.scroll_height(),
192        0f32,
193        "scroll_height of node {:?}. Expected {}. Actual {}",
194        node3,
195        0f32,
196        layout.scroll_height()
197    );
198    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
199    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
200    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
201    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
202    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
203    assert_eq!(location.y, 78f32, "y of node {:?}. Expected {}. Actual {}", node4, 78f32, location.y);
204    #[cfg(feature = "content_size")]
205    assert_eq!(
206        layout.scroll_width(),
207        0f32,
208        "scroll_width of node {:?}. Expected {}. Actual {}",
209        node4,
210        0f32,
211        layout.scroll_width()
212    );
213    #[cfg(feature = "content_size")]
214    assert_eq!(
215        layout.scroll_height(),
216        0f32,
217        "scroll_height of node {:?}. Expected {}. Actual {}",
218        node4,
219        0f32,
220        layout.scroll_height()
221    );
222    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
223    let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
224    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node5, 50f32, size.width);
225    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node5, 10f32, size.height);
226    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node5, 50f32, location.x);
227    assert_eq!(location.y, 78f32, "y of node {:?}. Expected {}. Actual {}", node5, 78f32, location.y);
228    #[cfg(feature = "content_size")]
229    assert_eq!(
230        layout.scroll_width(),
231        0f32,
232        "scroll_width of node {:?}. Expected {}. Actual {}",
233        node5,
234        0f32,
235        layout.scroll_width()
236    );
237    #[cfg(feature = "content_size")]
238    assert_eq!(
239        layout.scroll_height(),
240        0f32,
241        "scroll_height of node {:?}. Expected {}. Actual {}",
242        node5,
243        0f32,
244        layout.scroll_height()
245    );
246}