gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 976HTML 921Markdown 12TOML 82979 Definiciones

⎇ 0.5.x tests/generated/flex/gap_column_gap_wrap_align_stretch.rs Rust · 204 líneas · 8.3 KB Historia Quién tocó qué crudo

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

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