tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1118HTML 1044Markdown 12TOML 94787 Sutichaykuna

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