tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

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