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