gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 254C 19JavaScript 81371 Definiciones

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