gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ 0.5.x tests/generated/flex/bevy_issue_8017.rs Rust · 272 líneas · 11.0 KB Historia Quién tocó qué crudo

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

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