gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Sutichaykuna

⎇ 0.4.x tests/generated/grid/grid_margins_auto_margins_override_stretch.rs Rust · 295 siq'ikuna · 12.7 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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