gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 238TOML 3CSS 11112 Definiciones

⎇ 0.5.x tests/generated/flex/wrap_reverse_row_align_content_stretch.rs Rust · 210 líneas · 8.4 KB Historia Quién tocó qué crudo

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

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