tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Definiciones

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_repeat_mixed.rs Rust · 226 líneas · 15.0 KB Historia Quién tocó qué crudo

CSS Grid: named lines and areas (#840) c3e80008d · Nico Burns ·

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