tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/bevy_issue_7976_3_level.rs Rust · 166 lines · 7.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_7976_3_level__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_percent(1f32),
11                height: taffy::style::Dimension::from_percent(1f32),
12            },
13            padding: taffy::geometry::Rect {
14                left: length(5f32),
15                right: length(5f32),
16                top: length(5f32),
17                bottom: length(5f32),
18            },
19            ..Default::default()
20        })
21        .unwrap();
22    let node0 = taffy
23        .new_with_children(
24            taffy::style::Style {
25                min_size: taffy::geometry::Size {
26                    width: taffy::style::Dimension::from_length(40f32),
27                    height: taffy::style::Dimension::from_length(40f32),
28                },
29                margin: taffy::geometry::Rect {
30                    left: length(5f32),
31                    right: length(5f32),
32                    top: length(5f32),
33                    bottom: length(5f32),
34                },
35                padding: taffy::geometry::Rect {
36                    left: length(5f32),
37                    right: length(5f32),
38                    top: length(5f32),
39                    bottom: length(5f32),
40                },
41                ..Default::default()
42            },
43            &[node00],
44        )
45        .unwrap();
46    let node = taffy
47        .new_with_children(
48            taffy::style::Style {
49                align_content: Some(taffy::style::AlignContent::Start),
50                size: taffy::geometry::Size {
51                    width: taffy::style::Dimension::from_length(200f32),
52                    height: taffy::style::Dimension::from_length(200f32),
53                },
54                ..Default::default()
55            },
56            &[node0],
57        )
58        .unwrap();
59    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
60    println!("\nComputed tree:");
61    taffy.print_tree(node);
62    println!();
63    let layout = taffy.layout(node).unwrap();
64    let Layout { size, location, .. } = layout;
65    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
66    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
67    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
68    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
69    let layout = taffy.layout(node0).unwrap();
70    let Layout { size, location, .. } = layout;
71    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
72    assert_eq!(size.height, 190f32, "height of node {:?}. Expected {}. Actual {}", node0, 190f32, size.height);
73    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
74    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
75    let layout = taffy.layout(node00).unwrap();
76    let Layout { size, location, .. } = layout;
77    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node00, 30f32, size.width);
78    assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node00, 180f32, size.height);
79    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00, 5f32, location.x);
80    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00, 5f32, location.y);
81}
82
83#[test]
84#[allow(non_snake_case)]
85fn bevy_issue_7976_3_level__content_box() {
86    #[allow(unused_imports)]
87    use taffy::{prelude::*, Layout};
88    let mut taffy = crate::new_test_tree();
89    let node00 = taffy
90        .new_leaf(taffy::style::Style {
91            box_sizing: taffy::style::BoxSizing::ContentBox,
92            size: taffy::geometry::Size {
93                width: taffy::style::Dimension::from_percent(1f32),
94                height: taffy::style::Dimension::from_percent(1f32),
95            },
96            padding: taffy::geometry::Rect {
97                left: length(5f32),
98                right: length(5f32),
99                top: length(5f32),
100                bottom: length(5f32),
101            },
102            ..Default::default()
103        })
104        .unwrap();
105    let node0 = taffy
106        .new_with_children(
107            taffy::style::Style {
108                box_sizing: taffy::style::BoxSizing::ContentBox,
109                min_size: taffy::geometry::Size {
110                    width: taffy::style::Dimension::from_length(40f32),
111                    height: taffy::style::Dimension::from_length(40f32),
112                },
113                margin: taffy::geometry::Rect {
114                    left: length(5f32),
115                    right: length(5f32),
116                    top: length(5f32),
117                    bottom: length(5f32),
118                },
119                padding: taffy::geometry::Rect {
120                    left: length(5f32),
121                    right: length(5f32),
122                    top: length(5f32),
123                    bottom: length(5f32),
124                },
125                ..Default::default()
126            },
127            &[node00],
128        )
129        .unwrap();
130    let node = taffy
131        .new_with_children(
132            taffy::style::Style {
133                box_sizing: taffy::style::BoxSizing::ContentBox,
134                align_content: Some(taffy::style::AlignContent::Start),
135                size: taffy::geometry::Size {
136                    width: taffy::style::Dimension::from_length(200f32),
137                    height: taffy::style::Dimension::from_length(200f32),
138                },
139                ..Default::default()
140            },
141            &[node0],
142        )
143        .unwrap();
144    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
145    println!("\nComputed tree:");
146    taffy.print_tree(node);
147    println!();
148    let layout = taffy.layout(node).unwrap();
149    let Layout { size, location, .. } = layout;
150    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
151    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
152    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
153    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
154    let layout = taffy.layout(node0).unwrap();
155    let Layout { size, location, .. } = layout;
156    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
157    assert_eq!(size.height, 190f32, "height of node {:?}. Expected {}. Actual {}", node0, 190f32, size.height);
158    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
159    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
160    let layout = taffy.layout(node00).unwrap();
161    let Layout { size, location, .. } = layout;
162    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
163    assert_eq!(size.height, 190f32, "height of node {:?}. Expected {}. Actual {}", node00, 190f32, size.height);
164    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00, 5f32, location.x);
165    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00, 5f32, location.y);
166}