⎇ 0.4.x
tests/generated/grid/grid_min_content_flex_column.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn grid_min_content_flex_column() {
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\u{200b}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\u{200b}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\u{200b}HH",
31 writing_mode: crate::WritingMode::Horizontal,
32 _aspect_ratio: None,
33 },
34 )
35 .unwrap();
36 let node0 = taffy
37 .new_with_children(
38 taffy::style::Style {
39 display: taffy::style::Display::Flex,
40 flex_direction: taffy::style::FlexDirection::Column,
41 ..Default::default()
42 },
43 &[node00, node01, node02],
44 )
45 .unwrap();
46 let node = taffy
47 .new_with_children(
48 taffy::style::Style {
49 display: taffy::style::Display::Grid,
50 grid_template_rows: vec![length(40f32)],
51 grid_template_columns: vec![min_content()],
52 ..Default::default()
53 },
54 &[node0],
55 )
56 .unwrap();
57 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
58 println!("\nComputed tree:");
59 taffy.print_tree(node);
60 println!();
61 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
62 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
63 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
64 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
65 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
66 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
67 #[cfg(feature = "content_size")]
68 assert_eq!(
69 layout.scroll_width(),
70 0f32,
71 "scroll_width of node {:?}. Expected {}. Actual {}",
72 node,
73 0f32,
74 layout.scroll_width()
75 );
76 #[cfg(feature = "content_size")]
77 assert_eq!(
78 layout.scroll_height(),
79 20f32,
80 "scroll_height of node {:?}. Expected {}. Actual {}",
81 node,
82 20f32,
83 layout.scroll_height()
84 );
85 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
86 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
87 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
88 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
89 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
90 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
91 #[cfg(feature = "content_size")]
92 assert_eq!(
93 layout.scroll_width(),
94 0f32,
95 "scroll_width of node {:?}. Expected {}. Actual {}",
96 node0,
97 0f32,
98 layout.scroll_width()
99 );
100 #[cfg(feature = "content_size")]
101 assert_eq!(
102 layout.scroll_height(),
103 20f32,
104 "scroll_height of node {:?}. Expected {}. Actual {}",
105 node0,
106 20f32,
107 layout.scroll_height()
108 );
109 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
110 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
111 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
112 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
113 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
114 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
115 #[cfg(feature = "content_size")]
116 assert_eq!(
117 layout.scroll_width(),
118 0f32,
119 "scroll_width of node {:?}. Expected {}. Actual {}",
120 node00,
121 0f32,
122 layout.scroll_width()
123 );
124 #[cfg(feature = "content_size")]
125 assert_eq!(
126 layout.scroll_height(),
127 0f32,
128 "scroll_height of node {:?}. Expected {}. Actual {}",
129 node00,
130 0f32,
131 layout.scroll_height()
132 );
133 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
134 let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
135 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
136 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
137 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
138 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node01, 20f32, location.y);
139 #[cfg(feature = "content_size")]
140 assert_eq!(
141 layout.scroll_width(),
142 0f32,
143 "scroll_width of node {:?}. Expected {}. Actual {}",
144 node01,
145 0f32,
146 layout.scroll_width()
147 );
148 #[cfg(feature = "content_size")]
149 assert_eq!(
150 layout.scroll_height(),
151 0f32,
152 "scroll_height of node {:?}. Expected {}. Actual {}",
153 node01,
154 0f32,
155 layout.scroll_height()
156 );
157 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
158 let layout @ Layout { size, location, .. } = taffy.layout(node02).unwrap();
159 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
160 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02, 20f32, size.height);
161 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
162 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node02, 40f32, location.y);
163 #[cfg(feature = "content_size")]
164 assert_eq!(
165 layout.scroll_width(),
166 0f32,
167 "scroll_width of node {:?}. Expected {}. Actual {}",
168 node02,
169 0f32,
170 layout.scroll_width()
171 );
172 #[cfg(feature = "content_size")]
173 assert_eq!(
174 layout.scroll_height(),
175 0f32,
176 "scroll_height of node {:?}. Expected {}. Actual {}",
177 node02,
178 0f32,
179 layout.scroll_height()
180 );
181}