gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

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

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

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