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_column_fixed_size.rs Rust · 214 líneas · 8.5 KB Historia Quién tocó qué crudo

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

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