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