gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definitions

⎇ 0.4.x tests/generated/grid/grid_align_items_baseline_child_multiline.rs Rust · 251 lines · 10.1 KB History Who touched what raw

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

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