⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/flex/min_height_with_nested_fixed_height.rs
Historia
Quién tocó qué
crudo
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn min_height_with_nested_fixed_height__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node00 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(40f32),
11 height: taffy::style::Dimension::Length(40f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node0 = taffy
17 .new_with_children(
18 taffy::style::Style {
19 flex_direction: taffy::style::FlexDirection::Column,
20 align_self: Some(taffy::style::AlignSelf::FlexStart),
21 flex_shrink: 0f32,
22 min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(28f32) },
23 margin: taffy::geometry::Rect {
24 left: zero(),
25 right: zero(),
26 top: taffy::style::LengthPercentageAuto::Length(8f32),
27 bottom: taffy::style::LengthPercentageAuto::Length(9f32),
28 },
29 ..Default::default()
30 },
31 &[node00],
32 )
33 .unwrap();
34 let node = taffy
35 .new_with_children(
36 taffy::style::Style {
37 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(320f32), height: auto() },
38 min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(44f32) },
39 padding: taffy::geometry::Rect {
40 left: taffy::style::LengthPercentage::Length(16f32),
41 right: taffy::style::LengthPercentage::Length(16f32),
42 top: zero(),
43 bottom: zero(),
44 },
45 ..Default::default()
46 },
47 &[node0],
48 )
49 .unwrap();
50 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
51 println!("\nComputed tree:");
52 taffy.print_tree(node);
53 println!();
54 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
55 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
56 assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
57 assert_eq!(size.height, 57f32, "height of node {:?}. Expected {}. Actual {}", node, 57f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
60 #[cfg(feature = "content_size")]
61 assert_eq!(
62 layout.scroll_width(),
63 0f32,
64 "scroll_width of node {:?}. Expected {}. Actual {}",
65 node,
66 0f32,
67 layout.scroll_width()
68 );
69 #[cfg(feature = "content_size")]
70 assert_eq!(
71 layout.scroll_height(),
72 0f32,
73 "scroll_height of node {:?}. Expected {}. Actual {}",
74 node,
75 0f32,
76 layout.scroll_height()
77 );
78 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
79 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
80 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
81 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
82 assert_eq!(location.x, 16f32, "x of node {:?}. Expected {}. Actual {}", node0, 16f32, location.x);
83 assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
84 #[cfg(feature = "content_size")]
85 assert_eq!(
86 layout.scroll_width(),
87 0f32,
88 "scroll_width of node {:?}. Expected {}. Actual {}",
89 node0,
90 0f32,
91 layout.scroll_width()
92 );
93 #[cfg(feature = "content_size")]
94 assert_eq!(
95 layout.scroll_height(),
96 0f32,
97 "scroll_height of node {:?}. Expected {}. Actual {}",
98 node0,
99 0f32,
100 layout.scroll_height()
101 );
102 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
103 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
104 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
105 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
106 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
107 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
108 #[cfg(feature = "content_size")]
109 assert_eq!(
110 layout.scroll_width(),
111 0f32,
112 "scroll_width of node {:?}. Expected {}. Actual {}",
113 node00,
114 0f32,
115 layout.scroll_width()
116 );
117 #[cfg(feature = "content_size")]
118 assert_eq!(
119 layout.scroll_height(),
120 0f32,
121 "scroll_height of node {:?}. Expected {}. Actual {}",
122 node00,
123 0f32,
124 layout.scroll_height()
125 );
126}
127
128#[test]
129#[allow(non_snake_case)]
130fn min_height_with_nested_fixed_height__content_box() {
131 #[allow(unused_imports)]
132 use taffy::{prelude::*, tree::Layout, TaffyTree};
133 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
134 let node00 = taffy
135 .new_leaf(taffy::style::Style {
136 box_sizing: taffy::style::BoxSizing::ContentBox,
137 size: taffy::geometry::Size {
138 width: taffy::style::Dimension::Length(40f32),
139 height: taffy::style::Dimension::Length(40f32),
140 },
141 ..Default::default()
142 })
143 .unwrap();
144 let node0 = taffy
145 .new_with_children(
146 taffy::style::Style {
147 box_sizing: taffy::style::BoxSizing::ContentBox,
148 flex_direction: taffy::style::FlexDirection::Column,
149 align_self: Some(taffy::style::AlignSelf::FlexStart),
150 flex_shrink: 0f32,
151 min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(28f32) },
152 margin: taffy::geometry::Rect {
153 left: zero(),
154 right: zero(),
155 top: taffy::style::LengthPercentageAuto::Length(8f32),
156 bottom: taffy::style::LengthPercentageAuto::Length(9f32),
157 },
158 ..Default::default()
159 },
160 &[node00],
161 )
162 .unwrap();
163 let node = taffy
164 .new_with_children(
165 taffy::style::Style {
166 box_sizing: taffy::style::BoxSizing::ContentBox,
167 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(320f32), height: auto() },
168 min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(44f32) },
169 padding: taffy::geometry::Rect {
170 left: taffy::style::LengthPercentage::Length(16f32),
171 right: taffy::style::LengthPercentage::Length(16f32),
172 top: zero(),
173 bottom: zero(),
174 },
175 ..Default::default()
176 },
177 &[node0],
178 )
179 .unwrap();
180 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
181 println!("\nComputed tree:");
182 taffy.print_tree(node);
183 println!();
184 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
185 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
186 assert_eq!(size.width, 352f32, "width of node {:?}. Expected {}. Actual {}", node, 352f32, size.width);
187 assert_eq!(size.height, 57f32, "height of node {:?}. Expected {}. Actual {}", node, 57f32, size.height);
188 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
189 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
190 #[cfg(feature = "content_size")]
191 assert_eq!(
192 layout.scroll_width(),
193 0f32,
194 "scroll_width of node {:?}. Expected {}. Actual {}",
195 node,
196 0f32,
197 layout.scroll_width()
198 );
199 #[cfg(feature = "content_size")]
200 assert_eq!(
201 layout.scroll_height(),
202 0f32,
203 "scroll_height of node {:?}. Expected {}. Actual {}",
204 node,
205 0f32,
206 layout.scroll_height()
207 );
208 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
209 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
210 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
211 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
212 assert_eq!(location.x, 16f32, "x of node {:?}. Expected {}. Actual {}", node0, 16f32, location.x);
213 assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
214 #[cfg(feature = "content_size")]
215 assert_eq!(
216 layout.scroll_width(),
217 0f32,
218 "scroll_width of node {:?}. Expected {}. Actual {}",
219 node0,
220 0f32,
221 layout.scroll_width()
222 );
223 #[cfg(feature = "content_size")]
224 assert_eq!(
225 layout.scroll_height(),
226 0f32,
227 "scroll_height of node {:?}. Expected {}. Actual {}",
228 node0,
229 0f32,
230 layout.scroll_height()
231 );
232 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
233 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
234 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
235 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
236 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
237 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
238 #[cfg(feature = "content_size")]
239 assert_eq!(
240 layout.scroll_width(),
241 0f32,
242 "scroll_width of node {:?}. Expected {}. Actual {}",
243 node00,
244 0f32,
245 layout.scroll_width()
246 );
247 #[cfg(feature = "content_size")]
248 assert_eq!(
249 layout.scroll_height(),
250 0f32,
251 "scroll_height of node {:?}. Expected {}. Actual {}",
252 node00,
253 0f32,
254 layout.scroll_height()
255 );
256}