gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Sutichaykuna

⎇ 0.5.x tests/generated/flex/wrap_row_align_items_center.rs Rust · 177 siq'ikuna · 7.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn wrap_row_align_items_center() {
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(30f32),
10                height: taffy::style::Dimension::Length(10f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node1 = taffy
16        .new_leaf(taffy::style::Style {
17            size: taffy::geometry::Size {
18                width: taffy::style::Dimension::Length(30f32),
19                height: taffy::style::Dimension::Length(20f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node2 = taffy
25        .new_leaf(taffy::style::Style {
26            size: taffy::geometry::Size {
27                width: taffy::style::Dimension::Length(30f32),
28                height: taffy::style::Dimension::Length(30f32),
29            },
30            ..Default::default()
31        })
32        .unwrap();
33    let node3 = taffy
34        .new_leaf(taffy::style::Style {
35            size: taffy::geometry::Size {
36                width: taffy::style::Dimension::Length(30f32),
37                height: taffy::style::Dimension::Length(30f32),
38            },
39            ..Default::default()
40        })
41        .unwrap();
42    let node = taffy
43        .new_with_children(
44            taffy::style::Style {
45                flex_wrap: taffy::style::FlexWrap::Wrap,
46                align_items: Some(taffy::style::AlignItems::Center),
47                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
48                ..Default::default()
49            },
50            &[node0, node1, node2, node3],
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
60    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node, 60f32, 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, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
84    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
85    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
86    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, 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, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width);
108    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
109    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
110    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, 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, 30f32, "width of node {:?}. Expected {}. Actual {}", node2, 30f32, size.width);
132    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
133    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, 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, 30f32, "width of node {:?}. Expected {}. Actual {}", node3, 30f32, size.width);
156    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node3, 30f32, size.height);
157    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
158    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3, 30f32, 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}