tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/bevy_issue_16304.rs Rust · 182 lines · 9.6 KB History Who touched what raw

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

1#[test]
2#[allow(non_snake_case)]
3fn bevy_issue_16304__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node000 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(20f32),
11                height: taffy::style::Dimension::from_length(40f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node001 = taffy
17        .new_leaf(taffy::style::Style {
18            size: taffy::geometry::Size {
19                width: taffy::style::Dimension::from_length(20f32),
20                height: taffy::style::Dimension::from_length(40f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node00 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                display: taffy::style::Display::Flex,
29                flex_wrap: taffy::style::FlexWrap::Wrap,
30                gap: taffy::geometry::Size { width: length(10f32), height: length(10f32) },
31                min_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
32                ..Default::default()
33            },
34            &[node000, node001],
35        )
36        .unwrap();
37    let node0 = taffy
38        .new_with_children(
39            taffy::style::Style {
40                display: taffy::style::Display::Flex,
41                flex_direction: taffy::style::FlexDirection::Column,
42                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
43                ..Default::default()
44            },
45            &[node00],
46        )
47        .unwrap();
48    let node = taffy
49        .new_with_children(taffy::style::Style { display: taffy::style::Display::Flex, ..Default::default() }, &[node0])
50        .unwrap();
51    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
52    println!("\nComputed tree:");
53    taffy.print_tree(node);
54    println!();
55    let layout = taffy.layout(node).unwrap();
56    let Layout { size, location, .. } = layout;
57    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
58    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
61    let layout = taffy.layout(node0).unwrap();
62    let Layout { size, location, .. } = layout;
63    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
64    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
65    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
66    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
67    let layout = taffy.layout(node00).unwrap();
68    let Layout { size, location, .. } = layout;
69    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
70    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
73    let layout = taffy.layout(node000).unwrap();
74    let Layout { size, location, .. } = layout;
75    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node000, 20f32, size.width);
76    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node000, 40f32, size.height);
77    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
78    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
79    let layout = taffy.layout(node001).unwrap();
80    let Layout { size, location, .. } = layout;
81    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node001, 20f32, size.width);
82    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node001, 40f32, size.height);
83    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node001, 30f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node001, 0f32, location.y);
85}
86
87#[test]
88#[allow(non_snake_case)]
89fn bevy_issue_16304__content_box() {
90    #[allow(unused_imports)]
91    use taffy::{prelude::*, Layout};
92    let mut taffy = crate::new_test_tree();
93    let node000 = taffy
94        .new_leaf(taffy::style::Style {
95            box_sizing: taffy::style::BoxSizing::ContentBox,
96            size: taffy::geometry::Size {
97                width: taffy::style::Dimension::from_length(20f32),
98                height: taffy::style::Dimension::from_length(40f32),
99            },
100            ..Default::default()
101        })
102        .unwrap();
103    let node001 = taffy
104        .new_leaf(taffy::style::Style {
105            box_sizing: taffy::style::BoxSizing::ContentBox,
106            size: taffy::geometry::Size {
107                width: taffy::style::Dimension::from_length(20f32),
108                height: taffy::style::Dimension::from_length(40f32),
109            },
110            ..Default::default()
111        })
112        .unwrap();
113    let node00 = taffy
114        .new_with_children(
115            taffy::style::Style {
116                display: taffy::style::Display::Flex,
117                box_sizing: taffy::style::BoxSizing::ContentBox,
118                flex_wrap: taffy::style::FlexWrap::Wrap,
119                gap: taffy::geometry::Size { width: length(10f32), height: length(10f32) },
120                min_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
121                ..Default::default()
122            },
123            &[node000, node001],
124        )
125        .unwrap();
126    let node0 = taffy
127        .new_with_children(
128            taffy::style::Style {
129                display: taffy::style::Display::Flex,
130                box_sizing: taffy::style::BoxSizing::ContentBox,
131                flex_direction: taffy::style::FlexDirection::Column,
132                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
133                ..Default::default()
134            },
135            &[node00],
136        )
137        .unwrap();
138    let node = taffy
139        .new_with_children(
140            taffy::style::Style {
141                display: taffy::style::Display::Flex,
142                box_sizing: taffy::style::BoxSizing::ContentBox,
143                ..Default::default()
144            },
145            &[node0],
146        )
147        .unwrap();
148    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
149    println!("\nComputed tree:");
150    taffy.print_tree(node);
151    println!();
152    let layout = taffy.layout(node).unwrap();
153    let Layout { size, location, .. } = layout;
154    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
155    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
156    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
157    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
158    let layout = taffy.layout(node0).unwrap();
159    let Layout { size, location, .. } = layout;
160    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
161    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
162    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
163    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
164    let layout = taffy.layout(node00).unwrap();
165    let Layout { size, location, .. } = layout;
166    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
167    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
168    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
169    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
170    let layout = taffy.layout(node000).unwrap();
171    let Layout { size, location, .. } = layout;
172    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node000, 20f32, size.width);
173    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node000, 40f32, size.height);
174    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
175    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
176    let layout = taffy.layout(node001).unwrap();
177    let Layout { size, location, .. } = layout;
178    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node001, 20f32, size.width);
179    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node001, 40f32, size.height);
180    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node001, 30f32, location.x);
181    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node001, 0f32, location.y);
182}