tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definitions

⎇ float-layout tests/generated/flex/padding_center_child.rs Rust · 107 lines · 5.0 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_center_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 {
10                width: taffy::style::Dimension::from_length(10f32),
11                height: taffy::style::Dimension::from_length(10f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node = taffy
17        .new_with_children(
18            taffy::style::Style {
19                align_items: Some(taffy::style::AlignItems::Center),
20                justify_content: Some(taffy::style::JustifyContent::Center),
21                size: taffy::geometry::Size {
22                    width: taffy::style::Dimension::from_length(100f32),
23                    height: taffy::style::Dimension::from_length(100f32),
24                },
25                padding: taffy::geometry::Rect {
26                    left: length(10f32),
27                    right: length(20f32),
28                    top: length(10f32),
29                    bottom: length(20f32),
30                },
31                ..Default::default()
32            },
33            &[node0],
34        )
35        .unwrap();
36    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37    println!("\nComputed tree:");
38    taffy.print_tree(node);
39    println!();
40    let layout = taffy.layout(node).unwrap();
41    let Layout { size, location, .. } = layout;
42    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
43    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
44    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
45    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
46    let layout = taffy.layout(node0).unwrap();
47    let Layout { size, location, .. } = layout;
48    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
49    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
50    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0, 40f32, location.x);
51    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node0, 40f32, location.y);
52}
53
54#[test]
55#[allow(non_snake_case)]
56fn padding_center_child__content_box() {
57    #[allow(unused_imports)]
58    use taffy::{prelude::*, Layout};
59    let mut taffy = crate::new_test_tree();
60    let node0 = taffy
61        .new_leaf(taffy::style::Style {
62            box_sizing: taffy::style::BoxSizing::ContentBox,
63            size: taffy::geometry::Size {
64                width: taffy::style::Dimension::from_length(10f32),
65                height: taffy::style::Dimension::from_length(10f32),
66            },
67            ..Default::default()
68        })
69        .unwrap();
70    let node = taffy
71        .new_with_children(
72            taffy::style::Style {
73                box_sizing: taffy::style::BoxSizing::ContentBox,
74                align_items: Some(taffy::style::AlignItems::Center),
75                justify_content: Some(taffy::style::JustifyContent::Center),
76                size: taffy::geometry::Size {
77                    width: taffy::style::Dimension::from_length(100f32),
78                    height: taffy::style::Dimension::from_length(100f32),
79                },
80                padding: taffy::geometry::Rect {
81                    left: length(10f32),
82                    right: length(20f32),
83                    top: length(10f32),
84                    bottom: length(20f32),
85                },
86                ..Default::default()
87            },
88            &[node0],
89        )
90        .unwrap();
91    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
92    println!("\nComputed tree:");
93    taffy.print_tree(node);
94    println!();
95    let layout = taffy.layout(node).unwrap();
96    let Layout { size, location, .. } = layout;
97    assert_eq!(size.width, 130f32, "width of node {:?}. Expected {}. Actual {}", node, 130f32, size.width);
98    assert_eq!(size.height, 130f32, "height of node {:?}. Expected {}. Actual {}", node, 130f32, size.height);
99    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
100    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
101    let layout = taffy.layout(node0).unwrap();
102    let Layout { size, location, .. } = layout;
103    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
104    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
105    assert_eq!(location.x, 55f32, "x of node {:?}. Expected {}. Actual {}", node0, 55f32, location.x);
106    assert_eq!(location.y, 55f32, "y of node {:?}. Expected {}. Actual {}", node0, 55f32, location.y);
107}