tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1350 Definitions

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