gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 0.5.x tests/generated/flex/align_content_stretch_row_with_max_height.rs Rust · 199 líneas · 8.2 KB Historia Quién tocó qué crudo

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

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