gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Sutichaykuna

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