tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Sutichaykuna

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