tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/align_content_stretch.rs Rust · 191 líneas · 10.7 KB Historia Quién tocó qué crudo

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

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