gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 254C 19JavaScript 81372 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/align_baseline_child_multiline.rs Rust · 243 líneas · 9.7 KB Historia Quién tocó qué crudo

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

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