tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definiciones

⎇ 0.4.x tests/generated/grid/grid_align_items_baseline_multiline_column.rs Rust · 259 líneas · 10.3 KB Historia Quién tocó qué crudo

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

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