tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/padding_border_overrides_size.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_border_overrides_size__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(12f32),
11                height: taffy::style::Dimension::from_length(12f32),
12            },
13            padding: taffy::geometry::Rect {
14                left: length(8f32),
15                right: length(4f32),
16                top: length(2f32),
17                bottom: length(6f32),
18            },
19            border: taffy::geometry::Rect {
20                left: length(7f32),
21                right: length(3f32),
22                top: length(1f32),
23                bottom: length(5f32),
24            },
25            ..Default::default()
26        })
27        .unwrap();
28    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
29    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
30    println!("\nComputed tree:");
31    taffy.print_tree(node);
32    println!();
33    let layout = taffy.layout(node).unwrap();
34    let Layout { size, location, .. } = layout;
35    assert_eq!(size.width, 22f32, "width of node {:?}. Expected {}. Actual {}", node, 22f32, size.width);
36    assert_eq!(size.height, 14f32, "height of node {:?}. Expected {}. Actual {}", node, 14f32, size.height);
37    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
38    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
39    let layout = taffy.layout(node0).unwrap();
40    let Layout { size, location, .. } = layout;
41    assert_eq!(size.width, 22f32, "width of node {:?}. Expected {}. Actual {}", node0, 22f32, size.width);
42    assert_eq!(size.height, 14f32, "height of node {:?}. Expected {}. Actual {}", node0, 14f32, size.height);
43    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
44    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
45}
46
47#[test]
48#[allow(non_snake_case)]
49fn padding_border_overrides_size__content_box() {
50    #[allow(unused_imports)]
51    use taffy::{prelude::*, Layout};
52    let mut taffy = crate::new_test_tree();
53    let node0 = taffy
54        .new_leaf(taffy::style::Style {
55            box_sizing: taffy::style::BoxSizing::ContentBox,
56            size: taffy::geometry::Size {
57                width: taffy::style::Dimension::from_length(12f32),
58                height: taffy::style::Dimension::from_length(12f32),
59            },
60            padding: taffy::geometry::Rect {
61                left: length(8f32),
62                right: length(4f32),
63                top: length(2f32),
64                bottom: length(6f32),
65            },
66            border: taffy::geometry::Rect {
67                left: length(7f32),
68                right: length(3f32),
69                top: length(1f32),
70                bottom: length(5f32),
71            },
72            ..Default::default()
73        })
74        .unwrap();
75    let node = taffy
76        .new_with_children(
77            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
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, 34f32, "width of node {:?}. Expected {}. Actual {}", node, 34f32, size.width);
88    assert_eq!(size.height, 26f32, "height of node {:?}. Expected {}. Actual {}", node, 26f32, 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, 34f32, "width of node {:?}. Expected {}. Actual {}", node0, 34f32, size.width);
94    assert_eq!(size.height, 26f32, "height of node {:?}. Expected {}. Actual {}", node0, 26f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
97}