gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definitions

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/flex_direction_column_reverse_no_height.rs Rust · 275 lines · 11.2 KB History Who touched what raw

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn flex_direction_column_reverse_no_height__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
16            ..Default::default()
17        })
18        .unwrap();
19    let node2 = taffy
20        .new_leaf(taffy::style::Style {
21            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
22            ..Default::default()
23        })
24        .unwrap();
25    let node = taffy
26        .new_with_children(
27            taffy::style::Style {
28                flex_direction: taffy::style::FlexDirection::ColumnReverse,
29                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
30                ..Default::default()
31            },
32            &[node0, node1, node2],
33        )
34        .unwrap();
35    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
36    println!("\nComputed tree:");
37    taffy.print_tree(node);
38    println!();
39    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
40    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
41    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
42    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
43    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
44    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
45    #[cfg(feature = "content_size")]
46    assert_eq!(
47        layout.scroll_width(),
48        0f32,
49        "scroll_width of node {:?}. Expected {}. Actual {}",
50        node,
51        0f32,
52        layout.scroll_width()
53    );
54    #[cfg(feature = "content_size")]
55    assert_eq!(
56        layout.scroll_height(),
57        0f32,
58        "scroll_height of node {:?}. Expected {}. Actual {}",
59        node,
60        0f32,
61        layout.scroll_height()
62    );
63    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
64    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
65    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
66    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
67    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
68    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node0, 20f32, location.y);
69    #[cfg(feature = "content_size")]
70    assert_eq!(
71        layout.scroll_width(),
72        0f32,
73        "scroll_width of node {:?}. Expected {}. Actual {}",
74        node0,
75        0f32,
76        layout.scroll_width()
77    );
78    #[cfg(feature = "content_size")]
79    assert_eq!(
80        layout.scroll_height(),
81        0f32,
82        "scroll_height of node {:?}. Expected {}. Actual {}",
83        node0,
84        0f32,
85        layout.scroll_height()
86    );
87    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
88    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
89    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
90    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
91    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
92    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
93    #[cfg(feature = "content_size")]
94    assert_eq!(
95        layout.scroll_width(),
96        0f32,
97        "scroll_width of node {:?}. Expected {}. Actual {}",
98        node1,
99        0f32,
100        layout.scroll_width()
101    );
102    #[cfg(feature = "content_size")]
103    assert_eq!(
104        layout.scroll_height(),
105        0f32,
106        "scroll_height of node {:?}. Expected {}. Actual {}",
107        node1,
108        0f32,
109        layout.scroll_height()
110    );
111    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
112    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
113    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
114    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
115    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
116    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
117    #[cfg(feature = "content_size")]
118    assert_eq!(
119        layout.scroll_width(),
120        0f32,
121        "scroll_width of node {:?}. Expected {}. Actual {}",
122        node2,
123        0f32,
124        layout.scroll_width()
125    );
126    #[cfg(feature = "content_size")]
127    assert_eq!(
128        layout.scroll_height(),
129        0f32,
130        "scroll_height of node {:?}. Expected {}. Actual {}",
131        node2,
132        0f32,
133        layout.scroll_height()
134    );
135}
136
137#[test]
138#[allow(non_snake_case)]
139fn flex_direction_column_reverse_no_height__content_box() {
140    #[allow(unused_imports)]
141    use taffy::{prelude::*, tree::Layout, TaffyTree};
142    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
143    let node0 = taffy
144        .new_leaf(taffy::style::Style {
145            box_sizing: taffy::style::BoxSizing::ContentBox,
146            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
147            ..Default::default()
148        })
149        .unwrap();
150    let node1 = taffy
151        .new_leaf(taffy::style::Style {
152            box_sizing: taffy::style::BoxSizing::ContentBox,
153            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
154            ..Default::default()
155        })
156        .unwrap();
157    let node2 = taffy
158        .new_leaf(taffy::style::Style {
159            box_sizing: taffy::style::BoxSizing::ContentBox,
160            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
161            ..Default::default()
162        })
163        .unwrap();
164    let node = taffy
165        .new_with_children(
166            taffy::style::Style {
167                box_sizing: taffy::style::BoxSizing::ContentBox,
168                flex_direction: taffy::style::FlexDirection::ColumnReverse,
169                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
170                ..Default::default()
171            },
172            &[node0, node1, node2],
173        )
174        .unwrap();
175    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
176    println!("\nComputed tree:");
177    taffy.print_tree(node);
178    println!();
179    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
180    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
181    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
182    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
183    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
184    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 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        node,
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        node,
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(node0).unwrap();
205    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
206    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
207    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
208    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node0, 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        node0,
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        node0,
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(node1).unwrap();
229    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
230    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
231    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
232    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
233    #[cfg(feature = "content_size")]
234    assert_eq!(
235        layout.scroll_width(),
236        0f32,
237        "scroll_width of node {:?}. Expected {}. Actual {}",
238        node1,
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        node1,
248        0f32,
249        layout.scroll_height()
250    );
251    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
252    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
253    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
254    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
255    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
256    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
257    #[cfg(feature = "content_size")]
258    assert_eq!(
259        layout.scroll_width(),
260        0f32,
261        "scroll_width of node {:?}. Expected {}. Actual {}",
262        node2,
263        0f32,
264        layout.scroll_width()
265    );
266    #[cfg(feature = "content_size")]
267    assert_eq!(
268        layout.scroll_height(),
269        0f32,
270        "scroll_height of node {:?}. Expected {}. Actual {}",
271        node2,
272        0f32,
273        layout.scroll_height()
274    );
275}