gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1350 Definiciones

⎇ 0.4.x tests/generated/grid/grid_gap.rs Rust · 278 líneas · 12.0 KB Historia Quién tocó qué crudo

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

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