tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1116HTML 1041Markdown 12TOML 94780 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/block/block_absolute_margin_auto_left_without_inset.rs Rust · 107 siq'ikuna · 5.0 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_left_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: taffy::style::LengthPercentageAuto::AUTO,
16                right: zero(),
17                top: zero(),
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                size: taffy::geometry::Size {
28                    width: taffy::style::Dimension::from_length(200f32),
29                    height: taffy::style::Dimension::from_length(200f32),
30                },
31                ..Default::default()
32            },
33            &[node0],
34        )
35        .unwrap();
36    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37    println!("\nComputed tree:");
38    taffy.print_tree(node);
39    println!();
40    let layout = taffy.layout(node).unwrap();
41    let Layout { size, location, .. } = layout;
42    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
43    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
44    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
45    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
46    let layout = taffy.layout(node0).unwrap();
47    let Layout { size, location, .. } = layout;
48    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
49    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
52}
53
54#[test]
55#[allow(non_snake_case)]
56fn block_absolute_margin_auto_left_without_inset__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            position: taffy::style::Position::Absolute,
64            size: taffy::geometry::Size {
65                width: taffy::style::Dimension::from_length(50f32),
66                height: taffy::style::Dimension::from_length(50f32),
67            },
68            margin: taffy::geometry::Rect {
69                left: taffy::style::LengthPercentageAuto::AUTO,
70                right: zero(),
71                top: zero(),
72                bottom: zero(),
73            },
74            ..Default::default()
75        })
76        .unwrap();
77    let node = taffy
78        .new_with_children(
79            taffy::style::Style {
80                display: taffy::style::Display::Block,
81                box_sizing: taffy::style::BoxSizing::ContentBox,
82                size: taffy::geometry::Size {
83                    width: taffy::style::Dimension::from_length(200f32),
84                    height: taffy::style::Dimension::from_length(200f32),
85                },
86                ..Default::default()
87            },
88            &[node0],
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, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
98    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, 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, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
104    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, 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}