tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/absolute_child_with_cross_margin.rs Rust · 183 siq'ikuna · 9.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 absolute_child_with_cross_margin__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            align_content: Some(taffy::style::AlignContent::Stretch),
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_length(28f32),
12                height: taffy::style::Dimension::from_length(27f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy
18        .new_leaf_with_context(
19            taffy::style::Style {
20                position: taffy::style::Position::Absolute,
21                align_content: Some(taffy::style::AlignContent::Stretch),
22                flex_grow: 0f32,
23                flex_shrink: 1f32,
24                size: taffy::geometry::Size {
25                    width: taffy::style::Dimension::from_percent(1f32),
26                    height: taffy::style::Dimension::from_length(15f32),
27                },
28                margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(4f32), bottom: zero() },
29                ..Default::default()
30            },
31            crate::TestNodeContext::ahem_text("", crate::WritingMode::Horizontal),
32        )
33        .unwrap();
34    let node2 = taffy
35        .new_leaf(taffy::style::Style {
36            align_content: Some(taffy::style::AlignContent::Stretch),
37            size: taffy::geometry::Size {
38                width: taffy::style::Dimension::from_length(25f32),
39                height: taffy::style::Dimension::from_length(27f32),
40            },
41            ..Default::default()
42        })
43        .unwrap();
44    let node = taffy
45        .new_with_children(
46            taffy::style::Style {
47                justify_content: Some(taffy::style::JustifyContent::SpaceBetween),
48                min_size: taffy::geometry::Size {
49                    width: taffy::style::Dimension::from_length(311f32),
50                    height: taffy::style::Dimension::from_length(0f32),
51                },
52                max_size: taffy::geometry::Size {
53                    width: taffy::style::Dimension::from_length(311f32),
54                    height: taffy::style::Dimension::from_length(36893500000000000000f32),
55                },
56                ..Default::default()
57            },
58            &[node0, node1, node2],
59        )
60        .unwrap();
61    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
62    println!("\nComputed tree:");
63    taffy.print_tree(node);
64    println!();
65    let layout = taffy.layout(node).unwrap();
66    let Layout { size, location, .. } = layout;
67    assert_eq!(size.width, 311f32, "width of node {:?}. Expected {}. Actual {}", node, 311f32, size.width);
68    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node, 27f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
71    let layout = taffy.layout(node0).unwrap();
72    let Layout { size, location, .. } = layout;
73    assert_eq!(size.width, 28f32, "width of node {:?}. Expected {}. Actual {}", node0, 28f32, size.width);
74    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node0, 27f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
77    let layout = taffy.layout(node1).unwrap();
78    let Layout { size, location, .. } = layout;
79    assert_eq!(size.width, 311f32, "width of node {:?}. Expected {}. Actual {}", node1, 311f32, size.width);
80    assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node1, 15f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
82    assert_eq!(location.y, 4f32, "y of node {:?}. Expected {}. Actual {}", node1, 4f32, location.y);
83    let layout = taffy.layout(node2).unwrap();
84    let Layout { size, location, .. } = layout;
85    assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node2, 25f32, size.width);
86    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node2, 27f32, size.height);
87    assert_eq!(location.x, 286f32, "x of node {:?}. Expected {}. Actual {}", node2, 286f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
89}
90
91#[test]
92#[allow(non_snake_case)]
93fn absolute_child_with_cross_margin__content_box() {
94    #[allow(unused_imports)]
95    use taffy::{prelude::*, Layout};
96    let mut taffy = crate::new_test_tree();
97    let node0 = taffy
98        .new_leaf(taffy::style::Style {
99            box_sizing: taffy::style::BoxSizing::ContentBox,
100            align_content: Some(taffy::style::AlignContent::Stretch),
101            size: taffy::geometry::Size {
102                width: taffy::style::Dimension::from_length(28f32),
103                height: taffy::style::Dimension::from_length(27f32),
104            },
105            ..Default::default()
106        })
107        .unwrap();
108    let node1 = taffy
109        .new_leaf_with_context(
110            taffy::style::Style {
111                box_sizing: taffy::style::BoxSizing::ContentBox,
112                position: taffy::style::Position::Absolute,
113                align_content: Some(taffy::style::AlignContent::Stretch),
114                flex_grow: 0f32,
115                flex_shrink: 1f32,
116                size: taffy::geometry::Size {
117                    width: taffy::style::Dimension::from_percent(1f32),
118                    height: taffy::style::Dimension::from_length(15f32),
119                },
120                margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(4f32), bottom: zero() },
121                ..Default::default()
122            },
123            crate::TestNodeContext::ahem_text("", crate::WritingMode::Horizontal),
124        )
125        .unwrap();
126    let node2 = taffy
127        .new_leaf(taffy::style::Style {
128            box_sizing: taffy::style::BoxSizing::ContentBox,
129            align_content: Some(taffy::style::AlignContent::Stretch),
130            size: taffy::geometry::Size {
131                width: taffy::style::Dimension::from_length(25f32),
132                height: taffy::style::Dimension::from_length(27f32),
133            },
134            ..Default::default()
135        })
136        .unwrap();
137    let node = taffy
138        .new_with_children(
139            taffy::style::Style {
140                box_sizing: taffy::style::BoxSizing::ContentBox,
141                justify_content: Some(taffy::style::JustifyContent::SpaceBetween),
142                min_size: taffy::geometry::Size {
143                    width: taffy::style::Dimension::from_length(311f32),
144                    height: taffy::style::Dimension::from_length(0f32),
145                },
146                max_size: taffy::geometry::Size {
147                    width: taffy::style::Dimension::from_length(311f32),
148                    height: taffy::style::Dimension::from_length(36893500000000000000f32),
149                },
150                ..Default::default()
151            },
152            &[node0, node1, node2],
153        )
154        .unwrap();
155    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
156    println!("\nComputed tree:");
157    taffy.print_tree(node);
158    println!();
159    let layout = taffy.layout(node).unwrap();
160    let Layout { size, location, .. } = layout;
161    assert_eq!(size.width, 311f32, "width of node {:?}. Expected {}. Actual {}", node, 311f32, size.width);
162    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node, 27f32, size.height);
163    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
164    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
165    let layout = taffy.layout(node0).unwrap();
166    let Layout { size, location, .. } = layout;
167    assert_eq!(size.width, 28f32, "width of node {:?}. Expected {}. Actual {}", node0, 28f32, size.width);
168    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node0, 27f32, size.height);
169    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
170    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
171    let layout = taffy.layout(node1).unwrap();
172    let Layout { size, location, .. } = layout;
173    assert_eq!(size.width, 311f32, "width of node {:?}. Expected {}. Actual {}", node1, 311f32, size.width);
174    assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node1, 15f32, size.height);
175    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
176    assert_eq!(location.y, 4f32, "y of node {:?}. Expected {}. Actual {}", node1, 4f32, location.y);
177    let layout = taffy.layout(node2).unwrap();
178    let Layout { size, location, .. } = layout;
179    assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node2, 25f32, size.width);
180    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node2, 27f32, size.height);
181    assert_eq!(location.x, 286f32, "x of node {:?}. Expected {}. Actual {}", node2, 286f32, location.x);
182    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
183}