tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 998HTML 936Markdown 12TOML 83048 Definitions

⎇ 0.4.x tests/generated/grid/grid_minmax_column_fixed_width_below_range.rs Rust · 271 lines · 11.8 KB History Who touched what raw

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

1#[test]
2fn grid_minmax_column_fixed_width_below_range() {
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                grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
20                grid_template_columns: vec![length(40f32), minmax(length(20f32), length(40f32)), length(40f32)],
21                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(90f32), height: auto() },
22                ..Default::default()
23            },
24            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
25        )
26        .unwrap();
27    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
28    println!("\nComputed tree:");
29    taffy.print_tree(node);
30    println!();
31    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
32    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
33    assert_eq!(size.width, 90f32, "width of node {:?}. Expected {}. Actual {}", node, 90f32, size.width);
34    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
35    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
36    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
37    #[cfg(feature = "content_size")]
38    assert_eq!(
39        layout.scroll_width(),
40        10f32,
41        "scroll_width of node {:?}. Expected {}. Actual {}",
42        node,
43        10f32,
44        layout.scroll_width()
45    );
46    #[cfg(feature = "content_size")]
47    assert_eq!(
48        layout.scroll_height(),
49        0f32,
50        "scroll_height of node {:?}. Expected {}. Actual {}",
51        node,
52        0f32,
53        layout.scroll_height()
54    );
55    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
56    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
57    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
58    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 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        node0,
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        node0,
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(node1).unwrap();
81    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
82    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
83    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
85    #[cfg(feature = "content_size")]
86    assert_eq!(
87        layout.scroll_width(),
88        0f32,
89        "scroll_width of node {:?}. Expected {}. Actual {}",
90        node1,
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        node1,
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(node2).unwrap();
105    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
106    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
107    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
108    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
109    #[cfg(feature = "content_size")]
110    assert_eq!(
111        layout.scroll_width(),
112        0f32,
113        "scroll_width of node {:?}. Expected {}. Actual {}",
114        node2,
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        node2,
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(node3).unwrap();
129    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
130    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
131    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
132    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
133    #[cfg(feature = "content_size")]
134    assert_eq!(
135        layout.scroll_width(),
136        0f32,
137        "scroll_width of node {:?}. Expected {}. Actual {}",
138        node3,
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        node3,
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(node4).unwrap();
153    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4, 20f32, size.width);
154    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
155    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
156    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
157    #[cfg(feature = "content_size")]
158    assert_eq!(
159        layout.scroll_width(),
160        0f32,
161        "scroll_width of node {:?}. Expected {}. Actual {}",
162        node4,
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        node4,
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(node5).unwrap();
177    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node5, 40f32, size.width);
178    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
179    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5, 60f32, location.x);
180    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
181    #[cfg(feature = "content_size")]
182    assert_eq!(
183        layout.scroll_width(),
184        0f32,
185        "scroll_width of node {:?}. Expected {}. Actual {}",
186        node5,
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        node5,
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(node6).unwrap();
201    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node6, 40f32, size.width);
202    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6, 40f32, size.height);
203    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
204    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
205    #[cfg(feature = "content_size")]
206    assert_eq!(
207        layout.scroll_width(),
208        0f32,
209        "scroll_width of node {:?}. Expected {}. Actual {}",
210        node6,
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        node6,
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(node7).unwrap();
225    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node7, 20f32, size.width);
226    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node7, 40f32, size.height);
227    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
228    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
229    #[cfg(feature = "content_size")]
230    assert_eq!(
231        layout.scroll_width(),
232        0f32,
233        "scroll_width of node {:?}. Expected {}. Actual {}",
234        node7,
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        node7,
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(node8).unwrap();
249    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8, 40f32, size.width);
250    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8, 40f32, size.height);
251    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node8, 60f32, location.x);
252    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
253    #[cfg(feature = "content_size")]
254    assert_eq!(
255        layout.scroll_width(),
256        0f32,
257        "scroll_width of node {:?}. Expected {}. Actual {}",
258        node8,
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        node8,
268        0f32,
269        layout.scroll_height()
270    );
271}