tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

⎇ float-layout tests/generated/grid/grid_max_content_single_item_span_2.rs Rust · 223 lines · 14.7 KB History Who touched what raw

Add `taffy_test_helpers` crate (#755) 2a3e8476b · Nico Burns ·

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