tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1085HTML 1017Markdown 12TOML 84234 Definitions

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/padding_stretch_child.rs Rust · 97 lines · 4.6 KB History Who touched what raw

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn padding_stretch_child__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
10            ..Default::default()
11        })
12        .unwrap();
13    let node = taffy
14        .new_with_children(
15            taffy::style::Style {
16                size: taffy::geometry::Size {
17                    width: taffy::style::Dimension::from_length(100f32),
18                    height: taffy::style::Dimension::from_length(100f32),
19                },
20                padding: taffy::geometry::Rect {
21                    left: length(10f32),
22                    right: length(10f32),
23                    top: length(10f32),
24                    bottom: length(10f32),
25                },
26                ..Default::default()
27            },
28            &[node0],
29        )
30        .unwrap();
31    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
32    println!("\nComputed tree:");
33    taffy.print_tree(node);
34    println!();
35    let layout = taffy.layout(node).unwrap();
36    let Layout { size, location, .. } = layout;
37    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
38    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
39    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
40    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
41    let layout = taffy.layout(node0).unwrap();
42    let Layout { size, location, .. } = layout;
43    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
44    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
45    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0, 10f32, location.x);
46    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
47}
48
49#[test]
50#[allow(non_snake_case)]
51fn padding_stretch_child__content_box() {
52    #[allow(unused_imports)]
53    use taffy::{prelude::*, Layout};
54    let mut taffy = crate::new_test_tree();
55    let node0 = taffy
56        .new_leaf(taffy::style::Style {
57            box_sizing: taffy::style::BoxSizing::ContentBox,
58            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
59            ..Default::default()
60        })
61        .unwrap();
62    let node = taffy
63        .new_with_children(
64            taffy::style::Style {
65                box_sizing: taffy::style::BoxSizing::ContentBox,
66                size: taffy::geometry::Size {
67                    width: taffy::style::Dimension::from_length(100f32),
68                    height: taffy::style::Dimension::from_length(100f32),
69                },
70                padding: taffy::geometry::Rect {
71                    left: length(10f32),
72                    right: length(10f32),
73                    top: length(10f32),
74                    bottom: length(10f32),
75                },
76                ..Default::default()
77            },
78            &[node0],
79        )
80        .unwrap();
81    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
82    println!("\nComputed tree:");
83    taffy.print_tree(node);
84    println!();
85    let layout = taffy.layout(node).unwrap();
86    let Layout { size, location, .. } = layout;
87    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
88    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
89    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
90    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
91    let layout = taffy.layout(node0).unwrap();
92    let Layout { size, location, .. } = layout;
93    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
94    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
95    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0, 10f32, location.x);
96    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
97}