gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 238TOML 3CSS 11112 Definiciones

⎇ 0.5.x tests/generated/flex/absolute_layout_within_border.rs Rust · 230 líneas · 9.6 KB Historia Quién tocó qué crudo

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

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