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