gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 701HTML 654Markdown 12TOML 62332 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/rounding_total_fractial_nested.rs Rust · 221 líneas · 8.9 KB Historia Quién tocó qué crudo

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

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