tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definiciones

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/bevy_issue_9530.rs Rust · 246 líneas · 16.6 KB Historia Quién tocó qué crudo

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn bevy_issue_9530__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_direction: taffy::style::FlexDirection::Column,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_percent(1f32),
12                height: taffy::style::Dimension::from_length(20f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node10 = taffy
18        .new_leaf(taffy::style::Style {
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::from_percent(1f32),
21                height: taffy::style::Dimension::from_length(50f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node11 = taffy . new_leaf_with_context (taffy :: style :: Style { align_items : Some (taffy :: style :: AlignItems :: Center) , align_content : Some (taffy :: style :: AlignContent :: Center) , justify_content : Some (taffy :: style :: JustifyContent :: Center) , flex_grow : 1f32 , margin : taffy :: geometry :: Rect { left : length (20f32) , right : length (20f32) , top : length (20f32) , bottom : length (20f32) , } , .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ;
27    let node12 = taffy
28        .new_leaf(taffy::style::Style {
29            size: taffy::geometry::Size {
30                width: taffy::style::Dimension::from_percent(1f32),
31                height: taffy::style::Dimension::from_length(50f32),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node1 = taffy
37        .new_with_children(
38            taffy::style::Style {
39                flex_direction: taffy::style::FlexDirection::Column,
40                flex_grow: 1f32,
41                size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: auto() },
42                margin: taffy::geometry::Rect {
43                    left: length(20f32),
44                    right: length(20f32),
45                    top: length(20f32),
46                    bottom: length(20f32),
47                },
48                padding: taffy::geometry::Rect {
49                    left: length(20f32),
50                    right: length(20f32),
51                    top: length(20f32),
52                    bottom: length(20f32),
53                },
54                ..Default::default()
55            },
56            &[node10, node11, node12],
57        )
58        .unwrap();
59    let node = taffy
60        .new_with_children(
61            taffy::style::Style {
62                flex_direction: taffy::style::FlexDirection::Column,
63                align_items: Some(taffy::style::AlignItems::Center),
64                align_content: Some(taffy::style::AlignContent::Center),
65                size: taffy::geometry::Size {
66                    width: taffy::style::Dimension::from_length(300f32),
67                    height: taffy::style::Dimension::from_length(300f32),
68                },
69                margin: taffy::geometry::Rect {
70                    left: taffy::style::LengthPercentageAuto::AUTO,
71                    right: taffy::style::LengthPercentageAuto::AUTO,
72                    top: taffy::style::LengthPercentageAuto::AUTO,
73                    bottom: taffy::style::LengthPercentageAuto::AUTO,
74                },
75                ..Default::default()
76            },
77            &[node0, node1],
78        )
79        .unwrap();
80    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
81    println!("\nComputed tree:");
82    taffy.print_tree(node);
83    println!();
84    let layout = taffy.layout(node).unwrap();
85    let Layout { size, location, .. } = layout;
86    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node, 300f32, size.width);
87    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height);
88    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
89    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
90    let layout = taffy.layout(node0).unwrap();
91    let Layout { size, location, .. } = layout;
92    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width);
93    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
94    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
95    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
96    let layout = taffy.layout(node1).unwrap();
97    let Layout { size, location, .. } = layout;
98    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node1, 300f32, size.width);
99    assert_eq!(size.height, 420f32, "height of node {:?}. Expected {}. Actual {}", node1, 420f32, size.height);
100    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
101    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y);
102    let layout = taffy.layout(node10).unwrap();
103    let Layout { size, location, .. } = layout;
104    assert_eq!(size.width, 260f32, "width of node {:?}. Expected {}. Actual {}", node10, 260f32, size.width);
105    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node10, 50f32, size.height);
106    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node10, 20f32, location.x);
107    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node10, 20f32, location.y);
108    let layout = taffy.layout(node11).unwrap();
109    let Layout { size, location, .. } = layout;
110    assert_eq!(size.width, 220f32, "width of node {:?}. Expected {}. Actual {}", node11, 220f32, size.width);
111    assert_eq!(size.height, 240f32, "height of node {:?}. Expected {}. Actual {}", node11, 240f32, size.height);
112    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node11, 40f32, location.x);
113    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node11, 90f32, location.y);
114    let layout = taffy.layout(node12).unwrap();
115    let Layout { size, location, .. } = layout;
116    assert_eq!(size.width, 260f32, "width of node {:?}. Expected {}. Actual {}", node12, 260f32, size.width);
117    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node12, 50f32, size.height);
118    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node12, 20f32, location.x);
119    assert_eq!(location.y, 350f32, "y of node {:?}. Expected {}. Actual {}", node12, 350f32, location.y);
120}
121
122#[test]
123#[allow(non_snake_case)]
124fn bevy_issue_9530__content_box() {
125    #[allow(unused_imports)]
126    use taffy::{prelude::*, Layout};
127    let mut taffy = crate::new_test_tree();
128    let node0 = taffy
129        .new_leaf(taffy::style::Style {
130            box_sizing: taffy::style::BoxSizing::ContentBox,
131            flex_direction: taffy::style::FlexDirection::Column,
132            size: taffy::geometry::Size {
133                width: taffy::style::Dimension::from_percent(1f32),
134                height: taffy::style::Dimension::from_length(20f32),
135            },
136            ..Default::default()
137        })
138        .unwrap();
139    let node10 = taffy
140        .new_leaf(taffy::style::Style {
141            box_sizing: taffy::style::BoxSizing::ContentBox,
142            size: taffy::geometry::Size {
143                width: taffy::style::Dimension::from_percent(1f32),
144                height: taffy::style::Dimension::from_length(50f32),
145            },
146            ..Default::default()
147        })
148        .unwrap();
149    let node11 = taffy . new_leaf_with_context (taffy :: style :: Style { box_sizing : taffy :: style :: BoxSizing :: ContentBox , align_items : Some (taffy :: style :: AlignItems :: Center) , align_content : Some (taffy :: style :: AlignContent :: Center) , justify_content : Some (taffy :: style :: JustifyContent :: Center) , flex_grow : 1f32 , margin : taffy :: geometry :: Rect { left : length (20f32) , right : length (20f32) , top : length (20f32) , bottom : length (20f32) , } , .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ;
150    let node12 = taffy
151        .new_leaf(taffy::style::Style {
152            box_sizing: taffy::style::BoxSizing::ContentBox,
153            size: taffy::geometry::Size {
154                width: taffy::style::Dimension::from_percent(1f32),
155                height: taffy::style::Dimension::from_length(50f32),
156            },
157            ..Default::default()
158        })
159        .unwrap();
160    let node1 = taffy
161        .new_with_children(
162            taffy::style::Style {
163                box_sizing: taffy::style::BoxSizing::ContentBox,
164                flex_direction: taffy::style::FlexDirection::Column,
165                flex_grow: 1f32,
166                size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: auto() },
167                margin: taffy::geometry::Rect {
168                    left: length(20f32),
169                    right: length(20f32),
170                    top: length(20f32),
171                    bottom: length(20f32),
172                },
173                padding: taffy::geometry::Rect {
174                    left: length(20f32),
175                    right: length(20f32),
176                    top: length(20f32),
177                    bottom: length(20f32),
178                },
179                ..Default::default()
180            },
181            &[node10, node11, node12],
182        )
183        .unwrap();
184    let node = taffy
185        .new_with_children(
186            taffy::style::Style {
187                box_sizing: taffy::style::BoxSizing::ContentBox,
188                flex_direction: taffy::style::FlexDirection::Column,
189                align_items: Some(taffy::style::AlignItems::Center),
190                align_content: Some(taffy::style::AlignContent::Center),
191                size: taffy::geometry::Size {
192                    width: taffy::style::Dimension::from_length(300f32),
193                    height: taffy::style::Dimension::from_length(300f32),
194                },
195                margin: taffy::geometry::Rect {
196                    left: taffy::style::LengthPercentageAuto::AUTO,
197                    right: taffy::style::LengthPercentageAuto::AUTO,
198                    top: taffy::style::LengthPercentageAuto::AUTO,
199                    bottom: taffy::style::LengthPercentageAuto::AUTO,
200                },
201                ..Default::default()
202            },
203            &[node0, node1],
204        )
205        .unwrap();
206    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
207    println!("\nComputed tree:");
208    taffy.print_tree(node);
209    println!();
210    let layout = taffy.layout(node).unwrap();
211    let Layout { size, location, .. } = layout;
212    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node, 300f32, size.width);
213    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height);
214    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
215    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
216    let layout = taffy.layout(node0).unwrap();
217    let Layout { size, location, .. } = layout;
218    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width);
219    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
220    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
221    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
222    let layout = taffy.layout(node1).unwrap();
223    let Layout { size, location, .. } = layout;
224    assert_eq!(size.width, 340f32, "width of node {:?}. Expected {}. Actual {}", node1, 340f32, size.width);
225    assert_eq!(size.height, 380f32, "height of node {:?}. Expected {}. Actual {}", node1, 380f32, size.height);
226    assert_eq!(location.x, -20f32, "x of node {:?}. Expected {}. Actual {}", node1, -20f32, location.x);
227    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y);
228    let layout = taffy.layout(node10).unwrap();
229    let Layout { size, location, .. } = layout;
230    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node10, 300f32, size.width);
231    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node10, 50f32, size.height);
232    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node10, 20f32, location.x);
233    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node10, 20f32, location.y);
234    let layout = taffy.layout(node11).unwrap();
235    let Layout { size, location, .. } = layout;
236    assert_eq!(size.width, 260f32, "width of node {:?}. Expected {}. Actual {}", node11, 260f32, size.width);
237    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node11, 200f32, size.height);
238    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node11, 40f32, location.x);
239    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node11, 90f32, location.y);
240    let layout = taffy.layout(node12).unwrap();
241    let Layout { size, location, .. } = layout;
242    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node12, 300f32, size.width);
243    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node12, 50f32, size.height);
244    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node12, 20f32, location.x);
245    assert_eq!(location.y, 310f32, "y of node {:?}. Expected {}. Actual {}", node12, 310f32, location.y);
246}