tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 764HTML 710Markdown 12TOML 82508 Definiciones

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