gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 254C 19JavaScript 81371 Definitions

⎇ c154b8aa719da0d6f8636b123765a47fa40a3306 tests/generated/flex/bevy_issue_8082_percent.rs Rust · 219 lines · 8.9 KB History Who touched what raw

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

1#[test]
2fn bevy_issue_8082_percent() {
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(50f32),
10                height: taffy::style::Dimension::Length(50f32),
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(50f32),
19                height: taffy::style::Dimension::Length(50f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node02 = taffy
25        .new_leaf(taffy::style::Style {
26            size: taffy::geometry::Size {
27                width: taffy::style::Dimension::Length(50f32),
28                height: taffy::style::Dimension::Length(50f32),
29            },
30            ..Default::default()
31        })
32        .unwrap();
33    let node03 = taffy
34        .new_leaf(taffy::style::Style {
35            size: taffy::geometry::Size {
36                width: taffy::style::Dimension::Length(50f32),
37                height: taffy::style::Dimension::Length(50f32),
38            },
39            ..Default::default()
40        })
41        .unwrap();
42    let node0 = taffy
43        .new_with_children(
44            taffy::style::Style {
45                flex_wrap: taffy::style::FlexWrap::Wrap,
46                align_items: Some(taffy::style::AlignItems::FlexStart),
47                align_content: Some(taffy::style::AlignContent::Center),
48                justify_content: Some(taffy::style::JustifyContent::Center),
49                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
50                ..Default::default()
51            },
52            &[node00, node01, node02, node03],
53        )
54        .unwrap();
55    let node = taffy
56        .new_with_children(
57            taffy::style::Style {
58                flex_direction: taffy::style::FlexDirection::Column,
59                align_items: Some(taffy::style::AlignItems::Stretch),
60                align_content: Some(taffy::style::AlignContent::Center),
61                justify_content: Some(taffy::style::JustifyContent::FlexStart),
62                size: taffy::geometry::Size {
63                    width: taffy::style::Dimension::Length(200f32),
64                    height: taffy::style::Dimension::Length(400f32),
65                },
66                ..Default::default()
67            },
68            &[node0],
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, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
78    assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node, 400f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
102    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, 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, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
126    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, 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, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
150    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node01, 50f32, size.height);
151    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node01, 50f32, location.x);
152    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, 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(node02).unwrap();
173    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node02, 50f32, size.width);
174    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node02, 50f32, size.height);
175    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
176    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node02, 50f32, location.y);
177    #[cfg(feature = "content_size")]
178    assert_eq!(
179        layout.scroll_width(),
180        0f32,
181        "scroll_width of node {:?}. Expected {}. Actual {}",
182        node02,
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        node02,
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(node03).unwrap();
197    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node03, 50f32, size.width);
198    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node03, 50f32, size.height);
199    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node03, 50f32, location.x);
200    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node03, 50f32, location.y);
201    #[cfg(feature = "content_size")]
202    assert_eq!(
203        layout.scroll_width(),
204        0f32,
205        "scroll_width of node {:?}. Expected {}. Actual {}",
206        node03,
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        node03,
216        0f32,
217        layout.scroll_height()
218    );
219}