⎇ 0.4.x
tests/generated/grid/grid_absolute_layout_within_border_static.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn grid_absolute_layout_within_border_static() {
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 position: taffy::style::Position::Absolute,
9 align_self: Some(taffy::style::AlignSelf::Start),
10 justify_self: Some(taffy::style::JustifySelf::Start),
11 size: taffy::geometry::Size {
12 width: taffy::style::Dimension::Length(50f32),
13 height: taffy::style::Dimension::Length(50f32),
14 },
15 ..Default::default()
16 })
17 .unwrap();
18 let node1 = taffy
19 .new_leaf(taffy::style::Style {
20 position: taffy::style::Position::Absolute,
21 align_self: Some(taffy::style::AlignSelf::End),
22 justify_self: Some(taffy::style::JustifySelf::End),
23 size: taffy::geometry::Size {
24 width: taffy::style::Dimension::Length(50f32),
25 height: taffy::style::Dimension::Length(50f32),
26 },
27 ..Default::default()
28 })
29 .unwrap();
30 let node2 = taffy
31 .new_leaf(taffy::style::Style {
32 position: taffy::style::Position::Absolute,
33 align_self: Some(taffy::style::AlignSelf::Start),
34 justify_self: Some(taffy::style::JustifySelf::Start),
35 size: taffy::geometry::Size {
36 width: taffy::style::Dimension::Length(50f32),
37 height: taffy::style::Dimension::Length(50f32),
38 },
39 margin: taffy::geometry::Rect {
40 left: taffy::style::LengthPercentageAuto::Length(10f32),
41 right: taffy::style::LengthPercentageAuto::Length(10f32),
42 top: taffy::style::LengthPercentageAuto::Length(10f32),
43 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
44 },
45 ..Default::default()
46 })
47 .unwrap();
48 let node3 = taffy
49 .new_leaf(taffy::style::Style {
50 position: taffy::style::Position::Absolute,
51 align_self: Some(taffy::style::AlignSelf::End),
52 justify_self: Some(taffy::style::JustifySelf::End),
53 size: taffy::geometry::Size {
54 width: taffy::style::Dimension::Length(50f32),
55 height: taffy::style::Dimension::Length(50f32),
56 },
57 margin: taffy::geometry::Rect {
58 left: taffy::style::LengthPercentageAuto::Length(10f32),
59 right: taffy::style::LengthPercentageAuto::Length(10f32),
60 top: taffy::style::LengthPercentageAuto::Length(10f32),
61 bottom: taffy::style::LengthPercentageAuto::Length(10f32),
62 },
63 ..Default::default()
64 })
65 .unwrap();
66 let node = taffy
67 .new_with_children(
68 taffy::style::Style {
69 display: taffy::style::Display::Grid,
70 size: taffy::geometry::Size {
71 width: taffy::style::Dimension::Length(100f32),
72 height: taffy::style::Dimension::Length(100f32),
73 },
74 padding: taffy::geometry::Rect {
75 left: taffy::style::LengthPercentage::Length(10f32),
76 right: taffy::style::LengthPercentage::Length(10f32),
77 top: taffy::style::LengthPercentage::Length(10f32),
78 bottom: taffy::style::LengthPercentage::Length(10f32),
79 },
80 border: taffy::geometry::Rect {
81 left: taffy::style::LengthPercentage::Length(10f32),
82 right: taffy::style::LengthPercentage::Length(10f32),
83 top: taffy::style::LengthPercentage::Length(10f32),
84 bottom: taffy::style::LengthPercentage::Length(10f32),
85 },
86 ..Default::default()
87 },
88 &[node0, node1, node2, node3],
89 )
90 .unwrap();
91 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
92 println!("\nComputed tree:");
93 taffy.print_tree(node);
94 println!();
95 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
96 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
97 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
98 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
99 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
100 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 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 node,
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 node,
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(node0).unwrap();
121 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
122 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
123 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0, 10f32, location.x);
124 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
125 #[cfg(feature = "content_size")]
126 assert_eq!(
127 layout.scroll_width(),
128 0f32,
129 "scroll_width of node {:?}. Expected {}. Actual {}",
130 node0,
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 node0,
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(node1).unwrap();
145 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
146 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
147 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
148 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
149 #[cfg(feature = "content_size")]
150 assert_eq!(
151 layout.scroll_width(),
152 0f32,
153 "scroll_width of node {:?}. Expected {}. Actual {}",
154 node1,
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 node1,
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(node2).unwrap();
169 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
170 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
171 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node2, 20f32, location.x);
172 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2, 20f32, location.y);
173 #[cfg(feature = "content_size")]
174 assert_eq!(
175 layout.scroll_width(),
176 0f32,
177 "scroll_width of node {:?}. Expected {}. Actual {}",
178 node2,
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 node2,
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(node3).unwrap();
193 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
194 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3, 50f32, size.height);
195 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node3, 30f32, location.x);
196 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3, 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 node3,
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 node3,
212 0f32,
213 layout.scroll_height()
214 );
215}