gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Sutichaykuna

⎇ 0.5.x tests/generated/flex/align_content_stretch_row_with_fixed_height.rs Rust · 201 siq'ikuna · 8.1 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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