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