gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1064HTML 999Markdown 12TOML 83133 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/block/block_absolute_margin_auto_top_without_inset.rs Rust · 109 siq'ikuna · 5.1 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

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