gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/justify_content_row_flex_start.rs Rust · 281 líneas · 11.4 KB Historia Quién tocó qué crudo

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

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