tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1082HTML 1014Markdown 12TOML 83222 Definiciones

⎇ float-layout tests/generated/block/block_absolute_no_styles.rs Rust · 111 líneas · 5.6 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_absolute_no_styles__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::Block,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_length(50f32),
12                height: taffy::style::Dimension::from_length(10f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy
18        .new_leaf(taffy::style::Style {
19            display: taffy::style::Display::Block,
20            position: taffy::style::Position::Absolute,
21            ..Default::default()
22        })
23        .unwrap();
24    let node = taffy
25        .new_with_children(
26            taffy::style::Style { display: taffy::style::Display::Block, ..Default::default() },
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, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
37    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, 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, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
43    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, 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, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
52}
53
54#[test]
55#[allow(non_snake_case)]
56fn block_absolute_no_styles__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            display: taffy::style::Display::Block,
63            box_sizing: taffy::style::BoxSizing::ContentBox,
64            size: taffy::geometry::Size {
65                width: taffy::style::Dimension::from_length(50f32),
66                height: taffy::style::Dimension::from_length(10f32),
67            },
68            ..Default::default()
69        })
70        .unwrap();
71    let node1 = taffy
72        .new_leaf(taffy::style::Style {
73            display: taffy::style::Display::Block,
74            box_sizing: taffy::style::BoxSizing::ContentBox,
75            position: taffy::style::Position::Absolute,
76            ..Default::default()
77        })
78        .unwrap();
79    let node = taffy
80        .new_with_children(
81            taffy::style::Style {
82                display: taffy::style::Display::Block,
83                box_sizing: taffy::style::BoxSizing::ContentBox,
84                ..Default::default()
85            },
86            &[node0, node1],
87        )
88        .unwrap();
89    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
90    println!("\nComputed tree:");
91    taffy.print_tree(node);
92    println!();
93    let layout = taffy.layout(node).unwrap();
94    let Layout { size, location, .. } = layout;
95    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
96    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
97    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
98    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
99    let layout = taffy.layout(node0).unwrap();
100    let Layout { size, location, .. } = layout;
101    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
102    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
103    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
104    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
105    let layout = taffy.layout(node1).unwrap();
106    let Layout { size, location, .. } = layout;
107    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
108    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
109    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
110    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
111}