⎇ d875f416d56489ce545e5051d049603592195a63
tests/generated/flex/align_baseline_nested_column.rs
Historia
Quién tocó qué
crudo
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn align_baseline_nested_column() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size {
9 width: taffy::style::Dimension::Length(50f32),
10 height: taffy::style::Dimension::Length(60f32),
11 },
12 ..Default::default()
13 })
14 .unwrap();
15 let node100 = taffy
16 .new_leaf(taffy::style::Style {
17 flex_direction: taffy::style::FlexDirection::Column,
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Length(50f32),
20 height: taffy::style::Dimension::Length(30f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node101 = taffy
26 .new_leaf(taffy::style::Style {
27 flex_direction: taffy::style::FlexDirection::Column,
28 size: taffy::geometry::Size {
29 width: taffy::style::Dimension::Length(50f32),
30 height: taffy::style::Dimension::Length(40f32),
31 },
32 ..Default::default()
33 })
34 .unwrap();
35 let node10 = taffy
36 .new_with_children(
37 taffy::style::Style {
38 flex_direction: taffy::style::FlexDirection::Column,
39 size: taffy::geometry::Size {
40 width: taffy::style::Dimension::Length(50f32),
41 height: taffy::style::Dimension::Length(80f32),
42 },
43 ..Default::default()
44 },
45 &[node100, node101],
46 )
47 .unwrap();
48 let node1 = taffy
49 .new_with_children(
50 taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, ..Default::default() },
51 &[node10],
52 )
53 .unwrap();
54 let node = taffy
55 .new_with_children(
56 taffy::style::Style {
57 align_items: Some(taffy::style::AlignItems::Baseline),
58 size: taffy::geometry::Size {
59 width: taffy::style::Dimension::Length(100f32),
60 height: taffy::style::Dimension::Length(100f32),
61 },
62 ..Default::default()
63 },
64 &[node0, node1],
65 )
66 .unwrap();
67 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
68 println!("\nComputed tree:");
69 taffy.print_tree(node);
70 println!();
71 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
72 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
73 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
74 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
75 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
76 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
77 #[cfg(feature = "content_size")]
78 assert_eq!(
79 layout.scroll_width(),
80 0f32,
81 "scroll_width of node {:?}. Expected {}. Actual {}",
82 node,
83 0f32,
84 layout.scroll_width()
85 );
86 #[cfg(feature = "content_size")]
87 assert_eq!(
88 layout.scroll_height(),
89 10f32,
90 "scroll_height of node {:?}. Expected {}. Actual {}",
91 node,
92 10f32,
93 layout.scroll_height()
94 );
95 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
96 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
97 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
98 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0, 60f32, size.height);
99 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
100 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
101 #[cfg(feature = "content_size")]
102 assert_eq!(
103 layout.scroll_width(),
104 0f32,
105 "scroll_width of node {:?}. Expected {}. Actual {}",
106 node0,
107 0f32,
108 layout.scroll_width()
109 );
110 #[cfg(feature = "content_size")]
111 assert_eq!(
112 layout.scroll_height(),
113 0f32,
114 "scroll_height of node {:?}. Expected {}. Actual {}",
115 node0,
116 0f32,
117 layout.scroll_height()
118 );
119 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
120 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
121 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
122 assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node1, 80f32, size.height);
123 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
124 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1, 30f32, location.y);
125 #[cfg(feature = "content_size")]
126 assert_eq!(
127 layout.scroll_width(),
128 0f32,
129 "scroll_width of node {:?}. Expected {}. Actual {}",
130 node1,
131 0f32,
132 layout.scroll_width()
133 );
134 #[cfg(feature = "content_size")]
135 assert_eq!(
136 layout.scroll_height(),
137 0f32,
138 "scroll_height of node {:?}. Expected {}. Actual {}",
139 node1,
140 0f32,
141 layout.scroll_height()
142 );
143 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
144 let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
145 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
146 assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node10, 80f32, size.height);
147 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
148 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
149 #[cfg(feature = "content_size")]
150 assert_eq!(
151 layout.scroll_width(),
152 0f32,
153 "scroll_width of node {:?}. Expected {}. Actual {}",
154 node10,
155 0f32,
156 layout.scroll_width()
157 );
158 #[cfg(feature = "content_size")]
159 assert_eq!(
160 layout.scroll_height(),
161 0f32,
162 "scroll_height of node {:?}. Expected {}. Actual {}",
163 node10,
164 0f32,
165 layout.scroll_height()
166 );
167 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
168 let layout @ Layout { size, location, .. } = taffy.layout(node100).unwrap();
169 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node100, 50f32, size.width);
170 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node100, 30f32, size.height);
171 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node100, 0f32, location.x);
172 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node100, 0f32, location.y);
173 #[cfg(feature = "content_size")]
174 assert_eq!(
175 layout.scroll_width(),
176 0f32,
177 "scroll_width of node {:?}. Expected {}. Actual {}",
178 node100,
179 0f32,
180 layout.scroll_width()
181 );
182 #[cfg(feature = "content_size")]
183 assert_eq!(
184 layout.scroll_height(),
185 0f32,
186 "scroll_height of node {:?}. Expected {}. Actual {}",
187 node100,
188 0f32,
189 layout.scroll_height()
190 );
191 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
192 let layout @ Layout { size, location, .. } = taffy.layout(node101).unwrap();
193 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node101, 50f32, size.width);
194 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node101, 40f32, size.height);
195 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node101, 0f32, location.x);
196 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node101, 30f32, location.y);
197 #[cfg(feature = "content_size")]
198 assert_eq!(
199 layout.scroll_width(),
200 0f32,
201 "scroll_width of node {:?}. Expected {}. Actual {}",
202 node101,
203 0f32,
204 layout.scroll_width()
205 );
206 #[cfg(feature = "content_size")]
207 assert_eq!(
208 layout.scroll_height(),
209 0f32,
210 "scroll_height of node {:?}. Expected {}. Actual {}",
211 node101,
212 0f32,
213 layout.scroll_height()
214 );
215}