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