tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Definiciones

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_auto_single_item.rs Rust · 211 líneas · 14.2 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 grid_auto_single_item__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node1 = taffy
9        .new_leaf(taffy::style::Style {
10            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
11            ..Default::default()
12        })
13        .unwrap();
14    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
15    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
16    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
17    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18    let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19    let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20    let node8 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21    let node = taffy
22        .new_with_children(
23            taffy::style::Style {
24                display: taffy::style::Display::Grid,
25                grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
26                grid_template_columns: vec![length(40f32), auto(), length(40f32)],
27                ..Default::default()
28            },
29            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
30        )
31        .unwrap();
32    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
33    println!("\nComputed tree:");
34    taffy.print_tree(node);
35    println!();
36    let layout = taffy.layout(node).unwrap();
37    let Layout { size, location, .. } = layout;
38    assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
39    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
40    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
41    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
42    let layout = taffy.layout(node0).unwrap();
43    let Layout { size, location, .. } = layout;
44    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
45    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
46    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
47    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
48    let layout = taffy.layout(node1).unwrap();
49    let Layout { size, location, .. } = layout;
50    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
51    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
52    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
54    let layout = taffy.layout(node2).unwrap();
55    let Layout { size, location, .. } = layout;
56    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
57    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
58    assert_eq!(location.x, 140f32, "x of node {:?}. Expected {}. Actual {}", node2, 140f32, location.x);
59    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
60    let layout = taffy.layout(node3).unwrap();
61    let Layout { size, location, .. } = layout;
62    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
63    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
64    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
65    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
66    let layout = taffy.layout(node4).unwrap();
67    let Layout { size, location, .. } = layout;
68    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node4, 100f32, size.width);
69    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
70    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
71    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
72    let layout = taffy.layout(node5).unwrap();
73    let Layout { size, location, .. } = layout;
74    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node5, 40f32, size.width);
75    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
76    assert_eq!(location.x, 140f32, "x of node {:?}. Expected {}. Actual {}", node5, 140f32, location.x);
77    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
78    let layout = taffy.layout(node6).unwrap();
79    let Layout { size, location, .. } = layout;
80    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node6, 40f32, size.width);
81    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6, 40f32, size.height);
82    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
83    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
84    let layout = taffy.layout(node7).unwrap();
85    let Layout { size, location, .. } = layout;
86    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node7, 100f32, size.width);
87    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node7, 40f32, size.height);
88    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
89    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
90    let layout = taffy.layout(node8).unwrap();
91    let Layout { size, location, .. } = layout;
92    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8, 40f32, size.width);
93    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8, 40f32, size.height);
94    assert_eq!(location.x, 140f32, "x of node {:?}. Expected {}. Actual {}", node8, 140f32, location.x);
95    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
96}
97
98#[test]
99#[allow(non_snake_case)]
100fn grid_auto_single_item__content_box() {
101    #[allow(unused_imports)]
102    use taffy::{prelude::*, Layout};
103    let mut taffy = crate::new_test_tree();
104    let node0 = taffy
105        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
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(100f32), height: auto() },
111            ..Default::default()
112        })
113        .unwrap();
114    let node2 = taffy
115        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
116        .unwrap();
117    let node3 = taffy
118        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
119        .unwrap();
120    let node4 = taffy
121        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
122        .unwrap();
123    let node5 = taffy
124        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
125        .unwrap();
126    let node6 = taffy
127        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
128        .unwrap();
129    let node7 = taffy
130        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
131        .unwrap();
132    let node8 = taffy
133        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
134        .unwrap();
135    let node = taffy
136        .new_with_children(
137            taffy::style::Style {
138                display: taffy::style::Display::Grid,
139                box_sizing: taffy::style::BoxSizing::ContentBox,
140                grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
141                grid_template_columns: vec![length(40f32), auto(), length(40f32)],
142                ..Default::default()
143            },
144            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
145        )
146        .unwrap();
147    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
148    println!("\nComputed tree:");
149    taffy.print_tree(node);
150    println!();
151    let layout = taffy.layout(node).unwrap();
152    let Layout { size, location, .. } = layout;
153    assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
154    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
155    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
156    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
157    let layout = taffy.layout(node0).unwrap();
158    let Layout { size, location, .. } = layout;
159    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
160    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
161    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
162    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
163    let layout = taffy.layout(node1).unwrap();
164    let Layout { size, location, .. } = layout;
165    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
166    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
167    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
168    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
169    let layout = taffy.layout(node2).unwrap();
170    let Layout { size, location, .. } = layout;
171    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
172    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
173    assert_eq!(location.x, 140f32, "x of node {:?}. Expected {}. Actual {}", node2, 140f32, location.x);
174    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
175    let layout = taffy.layout(node3).unwrap();
176    let Layout { size, location, .. } = layout;
177    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
178    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
179    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
180    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3, 40f32, location.y);
181    let layout = taffy.layout(node4).unwrap();
182    let Layout { size, location, .. } = layout;
183    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node4, 100f32, size.width);
184    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
185    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node4, 40f32, location.x);
186    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4, 40f32, location.y);
187    let layout = taffy.layout(node5).unwrap();
188    let Layout { size, location, .. } = layout;
189    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node5, 40f32, size.width);
190    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
191    assert_eq!(location.x, 140f32, "x of node {:?}. Expected {}. Actual {}", node5, 140f32, location.x);
192    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5, 40f32, location.y);
193    let layout = taffy.layout(node6).unwrap();
194    let Layout { size, location, .. } = layout;
195    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node6, 40f32, size.width);
196    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node6, 40f32, size.height);
197    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node6, 0f32, location.x);
198    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node6, 80f32, location.y);
199    let layout = taffy.layout(node7).unwrap();
200    let Layout { size, location, .. } = layout;
201    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node7, 100f32, size.width);
202    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node7, 40f32, size.height);
203    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node7, 40f32, location.x);
204    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node7, 80f32, location.y);
205    let layout = taffy.layout(node8).unwrap();
206    let Layout { size, location, .. } = layout;
207    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node8, 40f32, size.width);
208    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node8, 40f32, size.height);
209    assert_eq!(location.x, 140f32, "x of node {:?}. Expected {}. Actual {}", node8, 140f32, location.x);
210    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node8, 80f32, location.y);
211}