tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

⎇ 477ff4aff498cbae4cdfbf0cda1ee5b04c784f08 tests/generated/flex/bevy_issue_9530.rs Rust · 227 siq'ikuna · 11.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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