tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1350 Definiciones

⎇ cd73db35cfa2b31555a796e7972cd97a45554e17 tests/generated/flex/gap_column_gap_wrap_align_space_between.rs Rust · 250 líneas · 10.0 KB Historia Quién tocó qué crudo

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

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