tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

⎇ float-layout tests/generated/flex/align_content_stretch_row.rs Rust · 189 líneas · 10.6 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_row__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_wrap: taffy::style::FlexWrap::Wrap,
41                align_content: Some(taffy::style::AlignContent::Stretch),
42                size: taffy::geometry::Size {
43                    width: taffy::style::Dimension::from_length(150f32),
44                    height: taffy::style::Dimension::from_length(100f32),
45                },
46                ..Default::default()
47            },
48            &[node0, node1, node2, node3, node4],
49        )
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, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
58    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, 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(node1).unwrap();
68    let Layout { size, location, .. } = layout;
69    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
70    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
71    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
73    let layout = taffy.layout(node2).unwrap();
74    let Layout { size, location, .. } = layout;
75    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
76    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
77    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node2, 100f32, location.x);
78    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
79    let layout = taffy.layout(node3).unwrap();
80    let Layout { size, location, .. } = layout;
81    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
82    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
84    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node3, 50f32, location.y);
85    let layout = taffy.layout(node4).unwrap();
86    let Layout { size, location, .. } = layout;
87    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
88    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
89    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4, 50f32, location.x);
90    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4, 50f32, location.y);
91}
92
93#[test]
94#[allow(non_snake_case)]
95fn align_content_stretch_row__content_box() {
96    #[allow(unused_imports)]
97    use taffy::{prelude::*, Layout};
98    let mut taffy = crate::new_test_tree();
99    let node0 = taffy
100        .new_leaf(taffy::style::Style {
101            box_sizing: taffy::style::BoxSizing::ContentBox,
102            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
103            ..Default::default()
104        })
105        .unwrap();
106    let node1 = taffy
107        .new_leaf(taffy::style::Style {
108            box_sizing: taffy::style::BoxSizing::ContentBox,
109            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
110            ..Default::default()
111        })
112        .unwrap();
113    let node2 = taffy
114        .new_leaf(taffy::style::Style {
115            box_sizing: taffy::style::BoxSizing::ContentBox,
116            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
117            ..Default::default()
118        })
119        .unwrap();
120    let node3 = taffy
121        .new_leaf(taffy::style::Style {
122            box_sizing: taffy::style::BoxSizing::ContentBox,
123            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
124            ..Default::default()
125        })
126        .unwrap();
127    let node4 = taffy
128        .new_leaf(taffy::style::Style {
129            box_sizing: taffy::style::BoxSizing::ContentBox,
130            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
131            ..Default::default()
132        })
133        .unwrap();
134    let node = taffy
135        .new_with_children(
136            taffy::style::Style {
137                box_sizing: taffy::style::BoxSizing::ContentBox,
138                flex_wrap: taffy::style::FlexWrap::Wrap,
139                align_content: Some(taffy::style::AlignContent::Stretch),
140                size: taffy::geometry::Size {
141                    width: taffy::style::Dimension::from_length(150f32),
142                    height: taffy::style::Dimension::from_length(100f32),
143                },
144                ..Default::default()
145            },
146            &[node0, node1, node2, node3, node4],
147        )
148        .unwrap();
149    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
150    println!("\nComputed tree:");
151    taffy.print_tree(node);
152    println!();
153    let layout = taffy.layout(node).unwrap();
154    let Layout { size, location, .. } = layout;
155    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
156    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
157    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
158    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
159    let layout = taffy.layout(node0).unwrap();
160    let Layout { size, location, .. } = layout;
161    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
162    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
163    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
164    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
165    let layout = taffy.layout(node1).unwrap();
166    let Layout { size, location, .. } = layout;
167    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
168    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
169    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
170    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
171    let layout = taffy.layout(node2).unwrap();
172    let Layout { size, location, .. } = layout;
173    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
174    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
175    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node2, 100f32, location.x);
176    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
177    let layout = taffy.layout(node3).unwrap();
178    let Layout { size, location, .. } = layout;
179    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
180    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
181    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
182    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node3, 50f32, location.y);
183    let layout = taffy.layout(node4).unwrap();
184    let Layout { size, location, .. } = layout;
185    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
186    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node4, 50f32, size.height);
187    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4, 50f32, location.x);
188    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node4, 50f32, location.y);
189}