gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 498HTML 254C 19JavaScript 81339 Definitions

⎇ 0.5.x tests/generated/flex/rounding_fractial_input_6.rs Rust · 243 lines · 9.6 KB History Who touched what raw

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

1#[test]
2fn rounding_fractial_input_6() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(2f32),
10                height: taffy::style::Dimension::Length(10f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node01 = taffy
16        .new_leaf(taffy::style::Style {
17            size: taffy::geometry::Size {
18                width: taffy::style::Dimension::Length(2f32),
19                height: taffy::style::Dimension::Length(10f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node0 = taffy
25        .new_with_children(
26            taffy::style::Style {
27                flex_wrap: taffy::style::FlexWrap::Wrap,
28                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
29                ..Default::default()
30            },
31            &[node00, node01],
32        )
33        .unwrap();
34    let node10 = taffy
35        .new_leaf(taffy::style::Style {
36            size: taffy::geometry::Size {
37                width: taffy::style::Dimension::Length(2f32),
38                height: taffy::style::Dimension::Length(10f32),
39            },
40            ..Default::default()
41        })
42        .unwrap();
43    let node11 = taffy
44        .new_leaf(taffy::style::Style {
45            size: taffy::geometry::Size {
46                width: taffy::style::Dimension::Length(2f32),
47                height: taffy::style::Dimension::Length(10f32),
48            },
49            ..Default::default()
50        })
51        .unwrap();
52    let node1 = taffy
53        .new_with_children(
54            taffy::style::Style {
55                flex_wrap: taffy::style::FlexWrap::Wrap,
56                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
57                ..Default::default()
58            },
59            &[node10, node11],
60        )
61        .unwrap();
62    let node = taffy
63        .new_with_children(
64            taffy::style::Style {
65                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(7f32), 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, 7f32, "width of node {:?}. Expected {}. Actual {}", node, 7f32, size.width);
78    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, 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, 4f32, "width of node {:?}. Expected {}. Actual {}", node0, 4f32, size.width);
102    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, 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(node00).unwrap();
125    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00, 2f32, size.width);
126    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
127    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
128    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
129    #[cfg(feature = "content_size")]
130    assert_eq!(
131        layout.scroll_width(),
132        0f32,
133        "scroll_width of node {:?}. Expected {}. Actual {}",
134        node00,
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        node00,
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(node01).unwrap();
149    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node01, 2f32, size.width);
150    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
151    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
152    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node01, 10f32, location.y);
153    #[cfg(feature = "content_size")]
154    assert_eq!(
155        layout.scroll_width(),
156        0f32,
157        "scroll_width of node {:?}. Expected {}. Actual {}",
158        node01,
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        node01,
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(node1).unwrap();
173    assert_eq!(size.width, 3f32, "width of node {:?}. Expected {}. Actual {}", node1, 3f32, size.width);
174    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
175    assert_eq!(location.x, 4f32, "x of node {:?}. Expected {}. Actual {}", node1, 4f32, location.x);
176    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 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        node1,
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        node1,
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(node10).unwrap();
197    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node10, 2f32, size.width);
198    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
199    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
200    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
201    #[cfg(feature = "content_size")]
202    assert_eq!(
203        layout.scroll_width(),
204        0f32,
205        "scroll_width of node {:?}. Expected {}. Actual {}",
206        node10,
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        node10,
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(node11).unwrap();
221    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node11, 2f32, size.width);
222    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node11, 10f32, size.height);
223    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node11, 0f32, location.x);
224    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node11, 10f32, location.y);
225    #[cfg(feature = "content_size")]
226    assert_eq!(
227        layout.scroll_width(),
228        0f32,
229        "scroll_width of node {:?}. Expected {}. Actual {}",
230        node11,
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        node11,
240        0f32,
241        layout.scroll_height()
242    );
243}