tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1076HTML 1008Markdown 12TOML 83208 Definiciones

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