gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 238TOML 3CSS 11131 Definiciones

⎇ d875f416d56489ce545e5051d049603592195a63 tests/generated/flex/wrap_nodes_with_content_sizing_margin_cross.rs Rust · 216 líneas · 8.5 KB Historia Quién tocó qué crudo

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

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