gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 976HTML 921Markdown 12TOML 82979 Definitions

⎇ 0.5.x tests/generated/flex/align_baseline_multiline_column.rs Rust · 255 lines · 10.1 KB History Who touched what raw

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn align_baseline_multiline_column() {
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            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(50f32),
10                height: taffy::style::Dimension::Length(50f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node10 = taffy
16        .new_leaf(taffy::style::Style {
17            size: taffy::geometry::Size {
18                width: taffy::style::Dimension::Length(20f32),
19                height: taffy::style::Dimension::Length(20f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node1 = taffy
25        .new_with_children(
26            taffy::style::Style {
27                flex_direction: taffy::style::FlexDirection::Column,
28                size: taffy::geometry::Size {
29                    width: taffy::style::Dimension::Length(30f32),
30                    height: taffy::style::Dimension::Length(50f32),
31                },
32                ..Default::default()
33            },
34            &[node10],
35        )
36        .unwrap();
37    let node20 = taffy
38        .new_leaf(taffy::style::Style {
39            size: taffy::geometry::Size {
40                width: taffy::style::Dimension::Length(10f32),
41                height: taffy::style::Dimension::Length(10f32),
42            },
43            ..Default::default()
44        })
45        .unwrap();
46    let node2 = taffy
47        .new_with_children(
48            taffy::style::Style {
49                flex_direction: taffy::style::FlexDirection::Column,
50                size: taffy::geometry::Size {
51                    width: taffy::style::Dimension::Length(40f32),
52                    height: taffy::style::Dimension::Length(70f32),
53                },
54                ..Default::default()
55            },
56            &[node20],
57        )
58        .unwrap();
59    let node3 = taffy
60        .new_leaf(taffy::style::Style {
61            size: taffy::geometry::Size {
62                width: taffy::style::Dimension::Length(50f32),
63                height: taffy::style::Dimension::Length(20f32),
64            },
65            ..Default::default()
66        })
67        .unwrap();
68    let node = taffy
69        .new_with_children(
70            taffy::style::Style {
71                flex_direction: taffy::style::FlexDirection::Column,
72                flex_wrap: taffy::style::FlexWrap::Wrap,
73                align_items: Some(taffy::style::AlignItems::Baseline),
74                size: taffy::geometry::Size {
75                    width: taffy::style::Dimension::Length(100f32),
76                    height: taffy::style::Dimension::Length(100f32),
77                },
78                ..Default::default()
79            },
80            &[node0, node1, node2, node3],
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
90    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
114    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
115    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
116    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, 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(node1).unwrap();
137    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width);
138    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
139    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
140    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
141    #[cfg(feature = "content_size")]
142    assert_eq!(
143        layout.scroll_width(),
144        0f32,
145        "scroll_width of node {:?}. Expected {}. Actual {}",
146        node1,
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        node1,
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(node10).unwrap();
161    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node10, 20f32, size.width);
162    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node10, 20f32, size.height);
163    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
164    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
165    #[cfg(feature = "content_size")]
166    assert_eq!(
167        layout.scroll_width(),
168        0f32,
169        "scroll_width of node {:?}. Expected {}. Actual {}",
170        node10,
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        node10,
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(node2).unwrap();
185    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
186    assert_eq!(size.height, 70f32, "height of node {:?}. Expected {}. Actual {}", node2, 70f32, size.height);
187    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
188    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
189    #[cfg(feature = "content_size")]
190    assert_eq!(
191        layout.scroll_width(),
192        0f32,
193        "scroll_width of node {:?}. Expected {}. Actual {}",
194        node2,
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        node2,
204        0f32,
205        layout.scroll_height()
206    );
207    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
208    let layout @ Layout { size, location, .. } = taffy.layout(node20).unwrap();
209    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node20, 10f32, size.width);
210    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20, 10f32, size.height);
211    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20, 0f32, location.x);
212    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y);
213    #[cfg(feature = "content_size")]
214    assert_eq!(
215        layout.scroll_width(),
216        0f32,
217        "scroll_width of node {:?}. Expected {}. Actual {}",
218        node20,
219        0f32,
220        layout.scroll_width()
221    );
222    #[cfg(feature = "content_size")]
223    assert_eq!(
224        layout.scroll_height(),
225        0f32,
226        "scroll_height of node {:?}. Expected {}. Actual {}",
227        node20,
228        0f32,
229        layout.scroll_height()
230    );
231    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
232    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
233    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
234    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
235    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3, 50f32, location.x);
236    assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node3, 70f32, location.y);
237    #[cfg(feature = "content_size")]
238    assert_eq!(
239        layout.scroll_width(),
240        0f32,
241        "scroll_width of node {:?}. Expected {}. Actual {}",
242        node3,
243        0f32,
244        layout.scroll_width()
245    );
246    #[cfg(feature = "content_size")]
247    assert_eq!(
248        layout.scroll_height(),
249        0f32,
250        "scroll_height of node {:?}. Expected {}. Actual {}",
251        node3,
252        0f32,
253        layout.scroll_height()
254    );
255}