tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/justify_content_column_center_negative_space_gap.rs Rust · 216 lines · 11.1 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 justify_content_column_center_negative_space_gap__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            flex_shrink: 0f32,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_percent(0.8f32),
12                height: taffy::style::Dimension::from_length(20f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node01 = taffy
18        .new_leaf(taffy::style::Style {
19            flex_shrink: 0f32,
20            size: taffy::geometry::Size {
21                width: taffy::style::Dimension::from_percent(0.8f32),
22                height: taffy::style::Dimension::from_length(20f32),
23            },
24            ..Default::default()
25        })
26        .unwrap();
27    let node02 = taffy
28        .new_leaf(taffy::style::Style {
29            flex_shrink: 0f32,
30            size: taffy::geometry::Size {
31                width: taffy::style::Dimension::from_percent(0.8f32),
32                height: taffy::style::Dimension::from_length(20f32),
33            },
34            ..Default::default()
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                align_items: Some(taffy::style::AlignItems::Center),
43                justify_content: Some(taffy::style::JustifyContent::Center),
44                gap: taffy::geometry::Size { width: length(10f32), height: length(10f32) },
45                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
46                ..Default::default()
47            },
48            &[node00, node01, node02],
49        )
50        .unwrap();
51    let node = taffy
52        .new_with_children(
53            taffy::style::Style {
54                display: taffy::style::Display::Flex,
55                flex_direction: taffy::style::FlexDirection::Column,
56                size: taffy::geometry::Size {
57                    width: taffy::style::Dimension::from_length(320f32),
58                    height: taffy::style::Dimension::from_length(320f32),
59                },
60                border: taffy::geometry::Rect {
61                    left: length(60f32),
62                    right: length(60f32),
63                    top: length(60f32),
64                    bottom: length(60f32),
65                },
66                ..Default::default()
67            },
68            &[node0],
69        )
70        .unwrap();
71    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
72    println!("\nComputed tree:");
73    taffy.print_tree(node);
74    println!();
75    let layout = taffy.layout(node).unwrap();
76    let Layout { size, location, .. } = layout;
77    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
78    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node, 320f32, size.height);
79    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
81    let layout = taffy.layout(node0).unwrap();
82    let Layout { size, location, .. } = layout;
83    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
84    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
85    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node0, 60f32, location.x);
86    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node0, 60f32, location.y);
87    let layout = taffy.layout(node00).unwrap();
88    let Layout { size, location, .. } = layout;
89    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
90    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
91    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
92    assert_eq!(location.y, -35f32, "y of node {:?}. Expected {}. Actual {}", node00, -35f32, location.y);
93    let layout = taffy.layout(node01).unwrap();
94    let Layout { size, location, .. } = layout;
95    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node01, 160f32, size.width);
96    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
97    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
98    assert_eq!(location.y, -5f32, "y of node {:?}. Expected {}. Actual {}", node01, -5f32, location.y);
99    let layout = taffy.layout(node02).unwrap();
100    let Layout { size, location, .. } = layout;
101    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node02, 160f32, size.width);
102    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02, 20f32, size.height);
103    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node02, 20f32, location.x);
104    assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node02, 25f32, location.y);
105}
106
107#[test]
108#[allow(non_snake_case)]
109fn justify_content_column_center_negative_space_gap__content_box() {
110    #[allow(unused_imports)]
111    use taffy::{prelude::*, Layout};
112    let mut taffy = crate::new_test_tree();
113    let node00 = taffy
114        .new_leaf(taffy::style::Style {
115            box_sizing: taffy::style::BoxSizing::ContentBox,
116            flex_shrink: 0f32,
117            size: taffy::geometry::Size {
118                width: taffy::style::Dimension::from_percent(0.8f32),
119                height: taffy::style::Dimension::from_length(20f32),
120            },
121            ..Default::default()
122        })
123        .unwrap();
124    let node01 = taffy
125        .new_leaf(taffy::style::Style {
126            box_sizing: taffy::style::BoxSizing::ContentBox,
127            flex_shrink: 0f32,
128            size: taffy::geometry::Size {
129                width: taffy::style::Dimension::from_percent(0.8f32),
130                height: taffy::style::Dimension::from_length(20f32),
131            },
132            ..Default::default()
133        })
134        .unwrap();
135    let node02 = taffy
136        .new_leaf(taffy::style::Style {
137            box_sizing: taffy::style::BoxSizing::ContentBox,
138            flex_shrink: 0f32,
139            size: taffy::geometry::Size {
140                width: taffy::style::Dimension::from_percent(0.8f32),
141                height: taffy::style::Dimension::from_length(20f32),
142            },
143            ..Default::default()
144        })
145        .unwrap();
146    let node0 = taffy
147        .new_with_children(
148            taffy::style::Style {
149                display: taffy::style::Display::Flex,
150                box_sizing: taffy::style::BoxSizing::ContentBox,
151                flex_direction: taffy::style::FlexDirection::Column,
152                align_items: Some(taffy::style::AlignItems::Center),
153                justify_content: Some(taffy::style::JustifyContent::Center),
154                gap: taffy::geometry::Size { width: length(10f32), height: length(10f32) },
155                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
156                ..Default::default()
157            },
158            &[node00, node01, node02],
159        )
160        .unwrap();
161    let node = taffy
162        .new_with_children(
163            taffy::style::Style {
164                display: taffy::style::Display::Flex,
165                box_sizing: taffy::style::BoxSizing::ContentBox,
166                flex_direction: taffy::style::FlexDirection::Column,
167                size: taffy::geometry::Size {
168                    width: taffy::style::Dimension::from_length(320f32),
169                    height: taffy::style::Dimension::from_length(320f32),
170                },
171                border: taffy::geometry::Rect {
172                    left: length(60f32),
173                    right: length(60f32),
174                    top: length(60f32),
175                    bottom: length(60f32),
176                },
177                ..Default::default()
178            },
179            &[node0],
180        )
181        .unwrap();
182    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
183    println!("\nComputed tree:");
184    taffy.print_tree(node);
185    println!();
186    let layout = taffy.layout(node).unwrap();
187    let Layout { size, location, .. } = layout;
188    assert_eq!(size.width, 440f32, "width of node {:?}. Expected {}. Actual {}", node, 440f32, size.width);
189    assert_eq!(size.height, 440f32, "height of node {:?}. Expected {}. Actual {}", node, 440f32, size.height);
190    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
191    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
192    let layout = taffy.layout(node0).unwrap();
193    let Layout { size, location, .. } = layout;
194    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node0, 320f32, size.width);
195    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
196    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node0, 60f32, location.x);
197    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node0, 60f32, location.y);
198    let layout = taffy.layout(node00).unwrap();
199    let Layout { size, location, .. } = layout;
200    assert_eq!(size.width, 256f32, "width of node {:?}. Expected {}. Actual {}", node00, 256f32, size.width);
201    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
202    assert_eq!(location.x, 32f32, "x of node {:?}. Expected {}. Actual {}", node00, 32f32, location.x);
203    assert_eq!(location.y, -35f32, "y of node {:?}. Expected {}. Actual {}", node00, -35f32, location.y);
204    let layout = taffy.layout(node01).unwrap();
205    let Layout { size, location, .. } = layout;
206    assert_eq!(size.width, 256f32, "width of node {:?}. Expected {}. Actual {}", node01, 256f32, size.width);
207    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
208    assert_eq!(location.x, 32f32, "x of node {:?}. Expected {}. Actual {}", node01, 32f32, location.x);
209    assert_eq!(location.y, -5f32, "y of node {:?}. Expected {}. Actual {}", node01, -5f32, location.y);
210    let layout = taffy.layout(node02).unwrap();
211    let Layout { size, location, .. } = layout;
212    assert_eq!(size.width, 256f32, "width of node {:?}. Expected {}. Actual {}", node02, 256f32, size.width);
213    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02, 20f32, size.height);
214    assert_eq!(location.x, 32f32, "x of node {:?}. Expected {}. Actual {}", node02, 32f32, location.x);
215    assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node02, 25f32, location.y);
216}