tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Sutichaykuna

⎇ cd73db35cfa2b31555a796e7972cd97a45554e17 tests/generated/flex/align_content_flex_start_with_flex.rs Rust · 211 siq'ikuna · 8.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn align_content_flex_start_with_flex() {
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            flex_grow: 1f32,
9            flex_shrink: 0f32,
10            flex_basis: taffy::style::Dimension::Percent(0f32),
11            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
12            ..Default::default()
13        })
14        .unwrap();
15    let node1 = taffy
16        .new_leaf(taffy::style::Style {
17            flex_grow: 1f32,
18            flex_shrink: 0f32,
19            flex_basis: taffy::style::Dimension::Percent(0f32),
20            size: taffy::geometry::Size {
21                width: taffy::style::Dimension::Length(50f32),
22                height: taffy::style::Dimension::Length(10f32),
23            },
24            ..Default::default()
25        })
26        .unwrap();
27    let node2 = taffy
28        .new_leaf(taffy::style::Style {
29            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
30            ..Default::default()
31        })
32        .unwrap();
33    let node3 = taffy
34        .new_leaf(taffy::style::Style {
35            flex_grow: 1f32,
36            flex_shrink: 1f32,
37            flex_basis: taffy::style::Dimension::Percent(0f32),
38            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
39            ..Default::default()
40        })
41        .unwrap();
42    let node4 = taffy
43        .new_leaf(taffy::style::Style {
44            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
45            ..Default::default()
46        })
47        .unwrap();
48    let node = taffy
49        .new_with_children(
50            taffy::style::Style {
51                flex_direction: taffy::style::FlexDirection::Column,
52                flex_wrap: taffy::style::FlexWrap::Wrap,
53                align_content: Some(taffy::style::AlignContent::FlexStart),
54                size: taffy::geometry::Size {
55                    width: taffy::style::Dimension::Length(100f32),
56                    height: taffy::style::Dimension::Length(120f32),
57                },
58                ..Default::default()
59            },
60            &[node0, node1, node2, node3, node4],
61        )
62        .unwrap();
63    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
64    println!("\nComputed tree:");
65    taffy.print_tree(node);
66    println!();
67    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
68    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
69    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
70    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
73    #[cfg(feature = "content_size")]
74    assert_eq!(
75        layout.scroll_width(),
76        0f32,
77        "scroll_width of node {:?}. Expected {}. Actual {}",
78        node,
79        0f32,
80        layout.scroll_width()
81    );
82    #[cfg(feature = "content_size")]
83    assert_eq!(
84        layout.scroll_height(),
85        0f32,
86        "scroll_height of node {:?}. Expected {}. Actual {}",
87        node,
88        0f32,
89        layout.scroll_height()
90    );
91    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
92    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
93    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
94    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
97    #[cfg(feature = "content_size")]
98    assert_eq!(
99        layout.scroll_width(),
100        0f32,
101        "scroll_width of node {:?}. Expected {}. Actual {}",
102        node0,
103        0f32,
104        layout.scroll_width()
105    );
106    #[cfg(feature = "content_size")]
107    assert_eq!(
108        layout.scroll_height(),
109        0f32,
110        "scroll_height of node {:?}. Expected {}. Actual {}",
111        node0,
112        0f32,
113        layout.scroll_height()
114    );
115    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
116    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
117    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
118    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
119    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
120    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
121    #[cfg(feature = "content_size")]
122    assert_eq!(
123        layout.scroll_width(),
124        0f32,
125        "scroll_width of node {:?}. Expected {}. Actual {}",
126        node1,
127        0f32,
128        layout.scroll_width()
129    );
130    #[cfg(feature = "content_size")]
131    assert_eq!(
132        layout.scroll_height(),
133        0f32,
134        "scroll_height of node {:?}. Expected {}. Actual {}",
135        node1,
136        0f32,
137        layout.scroll_height()
138    );
139    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
140    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
141    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
142    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node2, 0f32, size.height);
143    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
144    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node2, 80f32, location.y);
145    #[cfg(feature = "content_size")]
146    assert_eq!(
147        layout.scroll_width(),
148        0f32,
149        "scroll_width of node {:?}. Expected {}. Actual {}",
150        node2,
151        0f32,
152        layout.scroll_width()
153    );
154    #[cfg(feature = "content_size")]
155    assert_eq!(
156        layout.scroll_height(),
157        0f32,
158        "scroll_height of node {:?}. Expected {}. Actual {}",
159        node2,
160        0f32,
161        layout.scroll_height()
162    );
163    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
164    let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap();
165    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
166    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
167    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
168    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node3, 80f32, location.y);
169    #[cfg(feature = "content_size")]
170    assert_eq!(
171        layout.scroll_width(),
172        0f32,
173        "scroll_width of node {:?}. Expected {}. Actual {}",
174        node3,
175        0f32,
176        layout.scroll_width()
177    );
178    #[cfg(feature = "content_size")]
179    assert_eq!(
180        layout.scroll_height(),
181        0f32,
182        "scroll_height of node {:?}. Expected {}. Actual {}",
183        node3,
184        0f32,
185        layout.scroll_height()
186    );
187    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
188    let layout @ Layout { size, location, .. } = taffy.layout(node4).unwrap();
189    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
190    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node4, 0f32, size.height);
191    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4, 0f32, location.x);
192    assert_eq!(location.y, 120f32, "y of node {:?}. Expected {}. Actual {}", node4, 120f32, location.y);
193    #[cfg(feature = "content_size")]
194    assert_eq!(
195        layout.scroll_width(),
196        0f32,
197        "scroll_width of node {:?}. Expected {}. Actual {}",
198        node4,
199        0f32,
200        layout.scroll_width()
201    );
202    #[cfg(feature = "content_size")]
203    assert_eq!(
204        layout.scroll_height(),
205        0f32,
206        "scroll_height of node {:?}. Expected {}. Actual {}",
207        node4,
208        0f32,
209        layout.scroll_height()
210    );
211}