tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1082HTML 1014Markdown 12TOML 83222 Definitions

⎇ float-layout tests/generated/block/block_absolute_child_with_margin_x.rs Rust · 167 lines · 8.8 KB History Who touched what raw

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

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