tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1064HTML 999Markdown 12TOML 83137 Sutichaykuna

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