gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 498HTML 254C 19JavaScript 81339 Definiciones

⎇ 0.5.x tests/generated/flex/align_content_space_around_single_line.rs Rust · 245 líneas · 9.7 KB Historia Quién tocó qué crudo

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

1#[test]
2fn align_content_space_around_single_line() {
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                align_content: Some(taffy::style::AlignContent::SpaceAround),
64                size: taffy::geometry::Size {
65                    width: taffy::style::Dimension::Length(100f32),
66                    height: taffy::style::Dimension::Length(100f32),
67                },
68                ..Default::default()
69            },
70            &[node0, node1, node2, node3, node4, node5],
71        )
72        .unwrap();
73    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
74    println!("\nComputed tree:");
75    taffy.print_tree(node);
76    println!();
77    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
78    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
79    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
80    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
82    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
83    #[cfg(feature = "content_size")]
84    assert_eq!(
85        layout.scroll_width(),
86        0f32,
87        "scroll_width of node {:?}. Expected {}. Actual {}",
88        node,
89        0f32,
90        layout.scroll_width()
91    );
92    #[cfg(feature = "content_size")]
93    assert_eq!(
94        layout.scroll_height(),
95        0f32,
96        "scroll_height of node {:?}. Expected {}. Actual {}",
97        node,
98        0f32,
99        layout.scroll_height()
100    );
101    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
102    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
103    assert_eq!(size.width, 17f32, "width of node {:?}. Expected {}. Actual {}", node0, 17f32, size.width);
104    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
105    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
106    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
107    #[cfg(feature = "content_size")]
108    assert_eq!(
109        layout.scroll_width(),
110        0f32,
111        "scroll_width of node {:?}. Expected {}. Actual {}",
112        node0,
113        0f32,
114        layout.scroll_width()
115    );
116    #[cfg(feature = "content_size")]
117    assert_eq!(
118        layout.scroll_height(),
119        0f32,
120        "scroll_height of node {:?}. Expected {}. Actual {}",
121        node0,
122        0f32,
123        layout.scroll_height()
124    );
125    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
126    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
127    assert_eq!(size.width, 16f32, "width of node {:?}. Expected {}. Actual {}", node1, 16f32, size.width);
128    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
129    assert_eq!(location.x, 17f32, "x of node {:?}. Expected {}. Actual {}", node1, 17f32, location.x);
130    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
131    #[cfg(feature = "content_size")]
132    assert_eq!(
133        layout.scroll_width(),
134        0f32,
135        "scroll_width of node {:?}. Expected {}. Actual {}",
136        node1,
137        0f32,
138        layout.scroll_width()
139    );
140    #[cfg(feature = "content_size")]
141    assert_eq!(
142        layout.scroll_height(),
143        0f32,
144        "scroll_height of node {:?}. Expected {}. Actual {}",
145        node1,
146        0f32,
147        layout.scroll_height()
148    );
149    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
150    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
151    assert_eq!(size.width, 17f32, "width of node {:?}. Expected {}. Actual {}", node2, 17f32, size.width);
152    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
153    assert_eq!(location.x, 33f32, "x of node {:?}. Expected {}. Actual {}", node2, 33f32, location.x);
154    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
155    #[cfg(feature = "content_size")]
156    assert_eq!(
157        layout.scroll_width(),
158        0f32,
159        "scroll_width of node {:?}. Expected {}. Actual {}",
160        node2,
161        0f32,
162        layout.scroll_width()
163    );
164    #[cfg(feature = "content_size")]
165    assert_eq!(
166        layout.scroll_height(),
167        0f32,
168        "scroll_height of node {:?}. Expected {}. Actual {}",
169        node2,
170        0f32,
171        layout.scroll_height()
172    );
173    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
174    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
175    assert_eq!(size.width, 17f32, "width of node {:?}. Expected {}. Actual {}", node3, 17f32, size.width);
176    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
177    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
178    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
179    #[cfg(feature = "content_size")]
180    assert_eq!(
181        layout.scroll_width(),
182        0f32,
183        "scroll_width of node {:?}. Expected {}. Actual {}",
184        node3,
185        0f32,
186        layout.scroll_width()
187    );
188    #[cfg(feature = "content_size")]
189    assert_eq!(
190        layout.scroll_height(),
191        0f32,
192        "scroll_height of node {:?}. Expected {}. Actual {}",
193        node3,
194        0f32,
195        layout.scroll_height()
196    );
197    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
198    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
199    assert_eq!(size.width, 16f32, "width of node {:?}. Expected {}. Actual {}", node4, 16f32, size.width);
200    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
201    assert_eq!(location.x, 67f32, "x of node {:?}. Expected {}. Actual {}", node4, 67f32, location.x);
202    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
203    #[cfg(feature = "content_size")]
204    assert_eq!(
205        layout.scroll_width(),
206        0f32,
207        "scroll_width of node {:?}. Expected {}. Actual {}",
208        node4,
209        0f32,
210        layout.scroll_width()
211    );
212    #[cfg(feature = "content_size")]
213    assert_eq!(
214        layout.scroll_height(),
215        0f32,
216        "scroll_height of node {:?}. Expected {}. Actual {}",
217        node4,
218        0f32,
219        layout.scroll_height()
220    );
221    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
222    let layout @ Layout { size, location, .. } = taffy.layout(node5).unwrap();
223    assert_eq!(size.width, 17f32, "width of node {:?}. Expected {}. Actual {}", node5, 17f32, size.width);
224    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node5, 10f32, size.height);
225    assert_eq!(location.x, 83f32, "x of node {:?}. Expected {}. Actual {}", node5, 83f32, location.x);
226    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node5, 0f32, location.y);
227    #[cfg(feature = "content_size")]
228    assert_eq!(
229        layout.scroll_width(),
230        0f32,
231        "scroll_width of node {:?}. Expected {}. Actual {}",
232        node5,
233        0f32,
234        layout.scroll_width()
235    );
236    #[cfg(feature = "content_size")]
237    assert_eq!(
238        layout.scroll_height(),
239        0f32,
240        "scroll_height of node {:?}. Expected {}. Actual {}",
241        node5,
242        0f32,
243        layout.scroll_height()
244    );
245}