tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 709HTML 662Markdown 12TOML 62348 Sutichaykuna

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