tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/margin_auto_bottom.rs Rust · 136 siq'ikuna · 6.5 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 margin_auto_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            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(50f32),
11                height: taffy::style::Dimension::from_length(50f32),
12            },
13            margin: taffy::geometry::Rect {
14                left: zero(),
15                right: zero(),
16                top: zero(),
17                bottom: taffy::style::LengthPercentageAuto::AUTO,
18            },
19            ..Default::default()
20        })
21        .unwrap();
22    let node1 = taffy
23        .new_leaf(taffy::style::Style {
24            size: taffy::geometry::Size {
25                width: taffy::style::Dimension::from_length(50f32),
26                height: taffy::style::Dimension::from_length(50f32),
27            },
28            ..Default::default()
29        })
30        .unwrap();
31    let node = taffy
32        .new_with_children(
33            taffy::style::Style {
34                align_items: Some(taffy::style::AlignItems::Center),
35                size: taffy::geometry::Size {
36                    width: taffy::style::Dimension::from_length(200f32),
37                    height: taffy::style::Dimension::from_length(200f32),
38                },
39                ..Default::default()
40            },
41            &[node0, node1],
42        )
43        .unwrap();
44    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
45    println!("\nComputed tree:");
46    taffy.print_tree(node);
47    println!();
48    let layout = taffy.layout(node).unwrap();
49    let Layout { size, location, .. } = layout;
50    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
51    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
52    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
54    let layout = taffy.layout(node0).unwrap();
55    let Layout { size, location, .. } = layout;
56    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
57    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
58    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
59    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
60    let layout = taffy.layout(node1).unwrap();
61    let Layout { size, location, .. } = layout;
62    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
63    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
64    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
65    assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node1, 75f32, location.y);
66}
67
68#[test]
69#[allow(non_snake_case)]
70fn margin_auto_bottom__content_box() {
71    #[allow(unused_imports)]
72    use taffy::{prelude::*, Layout};
73    let mut taffy = crate::new_test_tree();
74    let node0 = taffy
75        .new_leaf(taffy::style::Style {
76            box_sizing: taffy::style::BoxSizing::ContentBox,
77            size: taffy::geometry::Size {
78                width: taffy::style::Dimension::from_length(50f32),
79                height: taffy::style::Dimension::from_length(50f32),
80            },
81            margin: taffy::geometry::Rect {
82                left: zero(),
83                right: zero(),
84                top: zero(),
85                bottom: taffy::style::LengthPercentageAuto::AUTO,
86            },
87            ..Default::default()
88        })
89        .unwrap();
90    let node1 = taffy
91        .new_leaf(taffy::style::Style {
92            box_sizing: taffy::style::BoxSizing::ContentBox,
93            size: taffy::geometry::Size {
94                width: taffy::style::Dimension::from_length(50f32),
95                height: taffy::style::Dimension::from_length(50f32),
96            },
97            ..Default::default()
98        })
99        .unwrap();
100    let node = taffy
101        .new_with_children(
102            taffy::style::Style {
103                box_sizing: taffy::style::BoxSizing::ContentBox,
104                align_items: Some(taffy::style::AlignItems::Center),
105                size: taffy::geometry::Size {
106                    width: taffy::style::Dimension::from_length(200f32),
107                    height: taffy::style::Dimension::from_length(200f32),
108                },
109                ..Default::default()
110            },
111            &[node0, node1],
112        )
113        .unwrap();
114    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
115    println!("\nComputed tree:");
116    taffy.print_tree(node);
117    println!();
118    let layout = taffy.layout(node).unwrap();
119    let Layout { size, location, .. } = layout;
120    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
121    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
122    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
123    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
124    let layout = taffy.layout(node0).unwrap();
125    let Layout { size, location, .. } = layout;
126    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
127    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
128    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
129    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
130    let layout = taffy.layout(node1).unwrap();
131    let Layout { size, location, .. } = layout;
132    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
133    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
134    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
135    assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node1, 75f32, location.y);
136}