tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/bevy_issue_10343_flex.rs Rust · 161 siq'ikuna · 8.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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