tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1100HTML 1031Markdown 12TOML 84455 Definitions

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