tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Sutichaykuna

⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227 tests/generated/flex/align_content_end_single_line_negative_space.rs Rust · 254 siq'ikuna · 10.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn align_content_end_single_line_negative_space__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_shrink: 0f32,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::Percent(0.8f32),
12                height: taffy::style::Dimension::Length(60f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node0 = taffy
18        .new_with_children(
19            taffy::style::Style {
20                display: taffy::style::Display::Flex,
21                align_content: Some(taffy::style::AlignContent::End),
22                justify_content: Some(taffy::style::JustifyContent::Center),
23                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
24                ..Default::default()
25            },
26            &[node00],
27        )
28        .unwrap();
29    let node = taffy
30        .new_with_children(
31            taffy::style::Style {
32                display: taffy::style::Display::Flex,
33                flex_direction: taffy::style::FlexDirection::Column,
34                size: taffy::geometry::Size {
35                    width: taffy::style::Dimension::Length(320f32),
36                    height: taffy::style::Dimension::Length(320f32),
37                },
38                border: taffy::geometry::Rect {
39                    left: taffy::style::LengthPercentage::Length(60f32),
40                    right: taffy::style::LengthPercentage::Length(60f32),
41                    top: taffy::style::LengthPercentage::Length(60f32),
42                    bottom: taffy::style::LengthPercentage::Length(60f32),
43                },
44                ..Default::default()
45            },
46            &[node0],
47        )
48        .unwrap();
49    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
50    println!("\nComputed tree:");
51    taffy.print_tree(node);
52    println!();
53    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
54    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
55    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
56    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node, 320f32, size.height);
57    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
58    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
59    #[cfg(feature = "content_size")]
60    assert_eq!(
61        layout.scroll_width(),
62        0f32,
63        "scroll_width of node {:?}. Expected {}. Actual {}",
64        node,
65        0f32,
66        layout.scroll_width()
67    );
68    #[cfg(feature = "content_size")]
69    assert_eq!(
70        layout.scroll_height(),
71        0f32,
72        "scroll_height of node {:?}. Expected {}. Actual {}",
73        node,
74        0f32,
75        layout.scroll_height()
76    );
77    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
78    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
79    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
80    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
81    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node0, 60f32, location.x);
82    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node0, 60f32, location.y);
83    #[cfg(feature = "content_size")]
84    assert_eq!(
85        layout.scroll_width(),
86        0f32,
87        "scroll_width of node {:?}. Expected {}. Actual {}",
88        node0,
89        0f32,
90        layout.scroll_width()
91    );
92    #[cfg(feature = "content_size")]
93    assert_eq!(
94        layout.scroll_height(),
95        50f32,
96        "scroll_height of node {:?}. Expected {}. Actual {}",
97        node0,
98        50f32,
99        layout.scroll_height()
100    );
101    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
102    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
103    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
104    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node00, 60f32, size.height);
105    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
106    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 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        node00,
113        0f32,
114        layout.scroll_width()
115    );
116    #[cfg(feature = "content_size")]
117    assert_eq!(
118        layout.scroll_height(),
119        0f32,
120        "scroll_height of node {:?}. Expected {}. Actual {}",
121        node00,
122        0f32,
123        layout.scroll_height()
124    );
125}
126
127#[test]
128#[allow(non_snake_case)]
129fn align_content_end_single_line_negative_space__content_box() {
130    #[allow(unused_imports)]
131    use taffy::{prelude::*, tree::Layout, TaffyTree};
132    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
133    let node00 = taffy
134        .new_leaf(taffy::style::Style {
135            box_sizing: taffy::style::BoxSizing::ContentBox,
136            flex_shrink: 0f32,
137            size: taffy::geometry::Size {
138                width: taffy::style::Dimension::Percent(0.8f32),
139                height: taffy::style::Dimension::Length(60f32),
140            },
141            ..Default::default()
142        })
143        .unwrap();
144    let node0 = taffy
145        .new_with_children(
146            taffy::style::Style {
147                display: taffy::style::Display::Flex,
148                box_sizing: taffy::style::BoxSizing::ContentBox,
149                align_content: Some(taffy::style::AlignContent::End),
150                justify_content: Some(taffy::style::JustifyContent::Center),
151                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
152                ..Default::default()
153            },
154            &[node00],
155        )
156        .unwrap();
157    let node = taffy
158        .new_with_children(
159            taffy::style::Style {
160                display: taffy::style::Display::Flex,
161                box_sizing: taffy::style::BoxSizing::ContentBox,
162                flex_direction: taffy::style::FlexDirection::Column,
163                size: taffy::geometry::Size {
164                    width: taffy::style::Dimension::Length(320f32),
165                    height: taffy::style::Dimension::Length(320f32),
166                },
167                border: taffy::geometry::Rect {
168                    left: taffy::style::LengthPercentage::Length(60f32),
169                    right: taffy::style::LengthPercentage::Length(60f32),
170                    top: taffy::style::LengthPercentage::Length(60f32),
171                    bottom: taffy::style::LengthPercentage::Length(60f32),
172                },
173                ..Default::default()
174            },
175            &[node0],
176        )
177        .unwrap();
178    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
179    println!("\nComputed tree:");
180    taffy.print_tree(node);
181    println!();
182    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
183    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
184    assert_eq!(size.width, 440f32, "width of node {:?}. Expected {}. Actual {}", node, 440f32, size.width);
185    assert_eq!(size.height, 440f32, "height of node {:?}. Expected {}. Actual {}", node, 440f32, size.height);
186    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
187    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
188    #[cfg(feature = "content_size")]
189    assert_eq!(
190        layout.scroll_width(),
191        0f32,
192        "scroll_width of node {:?}. Expected {}. Actual {}",
193        node,
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        node,
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(node0).unwrap();
208    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node0, 320f32, size.width);
209    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
210    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node0, 60f32, location.x);
211    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node0, 60f32, location.y);
212    #[cfg(feature = "content_size")]
213    assert_eq!(
214        layout.scroll_width(),
215        0f32,
216        "scroll_width of node {:?}. Expected {}. Actual {}",
217        node0,
218        0f32,
219        layout.scroll_width()
220    );
221    #[cfg(feature = "content_size")]
222    assert_eq!(
223        layout.scroll_height(),
224        50f32,
225        "scroll_height of node {:?}. Expected {}. Actual {}",
226        node0,
227        50f32,
228        layout.scroll_height()
229    );
230    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
231    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
232    assert_eq!(size.width, 256f32, "width of node {:?}. Expected {}. Actual {}", node00, 256f32, size.width);
233    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node00, 60f32, size.height);
234    assert_eq!(location.x, 32f32, "x of node {:?}. Expected {}. Actual {}", node00, 32f32, location.x);
235    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
236    #[cfg(feature = "content_size")]
237    assert_eq!(
238        layout.scroll_width(),
239        0f32,
240        "scroll_width of node {:?}. Expected {}. Actual {}",
241        node00,
242        0f32,
243        layout.scroll_width()
244    );
245    #[cfg(feature = "content_size")]
246    assert_eq!(
247        layout.scroll_height(),
248        0f32,
249        "scroll_height of node {:?}. Expected {}. Actual {}",
250        node00,
251        0f32,
252        layout.scroll_height()
253    );
254}