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