gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Sutichaykuna

⎇ 0.5.x tests/generated/flex/simple_child.rs Rust · 244 siq'ikuna · 9.7 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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