tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Definiciones

⎇ float-layout tests/generated/block/block_padding_intrinsic_size.rs Rust · 122 líneas · 6.0 KB Historia Quién tocó qué crudo

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

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