tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

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