tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Definitions

⎇ ae87fd0283feff32a5ceffe4c77394ff6ca88d39 tests/generated/rounding_fractial_input_7.rs Rust · 197 lines · 11.1 KB History Who touched what raw

Fix 1px wide gaps between adjacent UI nodes (#374) e8253b1ae · Nico Burns ·

1#[test]
2fn rounding_fractial_input_7() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Points(1f32),
11                height: taffy::style::Dimension::Points(10f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node01 = taffy
17        .new_leaf(taffy::style::Style {
18            size: taffy::geometry::Size {
19                width: taffy::style::Dimension::Points(1f32),
20                height: taffy::style::Dimension::Points(10f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node0 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                flex_wrap: taffy::style::FlexWrap::Wrap,
29                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.25f32), height: auto() },
30                ..Default::default()
31            },
32            &[node00, node01],
33        )
34        .unwrap();
35    let node10 = taffy
36        .new_leaf(taffy::style::Style {
37            size: taffy::geometry::Size {
38                width: taffy::style::Dimension::Points(1f32),
39                height: taffy::style::Dimension::Points(10f32),
40            },
41            ..Default::default()
42        })
43        .unwrap();
44    let node11 = taffy
45        .new_leaf(taffy::style::Style {
46            size: taffy::geometry::Size {
47                width: taffy::style::Dimension::Points(1f32),
48                height: taffy::style::Dimension::Points(10f32),
49            },
50            ..Default::default()
51        })
52        .unwrap();
53    let node1 = taffy
54        .new_with_children(
55            taffy::style::Style {
56                flex_wrap: taffy::style::FlexWrap::Wrap,
57                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.25f32), height: auto() },
58                ..Default::default()
59            },
60            &[node10, node11],
61        )
62        .unwrap();
63    let node20 = taffy
64        .new_leaf(taffy::style::Style {
65            size: taffy::geometry::Size {
66                width: taffy::style::Dimension::Points(1f32),
67                height: taffy::style::Dimension::Points(10f32),
68            },
69            ..Default::default()
70        })
71        .unwrap();
72    let node21 = taffy
73        .new_leaf(taffy::style::Style {
74            size: taffy::geometry::Size {
75                width: taffy::style::Dimension::Points(1f32),
76                height: taffy::style::Dimension::Points(10f32),
77            },
78            ..Default::default()
79        })
80        .unwrap();
81    let node2 = taffy
82        .new_with_children(
83            taffy::style::Style {
84                flex_wrap: taffy::style::FlexWrap::Wrap,
85                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.25f32), height: auto() },
86                ..Default::default()
87            },
88            &[node20, node21],
89        )
90        .unwrap();
91    let node30 = taffy
92        .new_leaf(taffy::style::Style {
93            size: taffy::geometry::Size {
94                width: taffy::style::Dimension::Points(1f32),
95                height: taffy::style::Dimension::Points(10f32),
96            },
97            ..Default::default()
98        })
99        .unwrap();
100    let node31 = taffy
101        .new_leaf(taffy::style::Style {
102            size: taffy::geometry::Size {
103                width: taffy::style::Dimension::Points(1f32),
104                height: taffy::style::Dimension::Points(10f32),
105            },
106            ..Default::default()
107        })
108        .unwrap();
109    let node3 = taffy
110        .new_with_children(
111            taffy::style::Style {
112                flex_wrap: taffy::style::FlexWrap::Wrap,
113                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.25f32), height: auto() },
114                ..Default::default()
115            },
116            &[node30, node31],
117        )
118        .unwrap();
119    let node = taffy
120        .new_with_children(
121            taffy::style::Style {
122                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(7f32), height: auto() },
123                ..Default::default()
124            },
125            &[node0, node1, node2, node3],
126        )
127        .unwrap();
128    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
129    println!("\nComputed tree:");
130    taffy::debug::print_tree(&taffy, node);
131    println!();
132    let Layout { size, location, .. } = taffy.layout(node).unwrap();
133    assert_eq!(size.width, 7f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 7f32, size.width);
134    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.height);
135    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
136    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
137    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
138    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 2f32, size.width);
139    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
140    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
141    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
142    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
143    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 1f32, size.width);
144    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, size.height);
145    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
146    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
147    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
148    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 1f32, size.width);
149    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 10f32, size.height);
150    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.x);
151    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 10f32, location.y);
152    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
153    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 2f32, size.width);
154    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
155    assert_eq!(location.x, 2f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 2f32, location.x);
156    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
157    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
158    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 1f32, size.width);
159    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 10f32, size.height);
160    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
161    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
162    let Layout { size, location, .. } = taffy.layout(node11).unwrap();
163    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node11.data(), 1f32, size.width);
164    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node11.data(), 10f32, size.height);
165    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node11.data(), 0f32, location.x);
166    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node11.data(), 10f32, location.y);
167    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
168    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 1f32, size.width);
169    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.height);
170    assert_eq!(location.x, 4f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 4f32, location.x);
171    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
172    let Layout { size, location, .. } = taffy.layout(node20).unwrap();
173    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node20.data(), 1f32, size.width);
174    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20.data(), 10f32, size.height);
175    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20.data(), 0f32, location.x);
176    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20.data(), 0f32, location.y);
177    let Layout { size, location, .. } = taffy.layout(node21).unwrap();
178    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node21.data(), 1f32, size.width);
179    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node21.data(), 10f32, size.height);
180    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node21.data(), 0f32, location.x);
181    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node21.data(), 10f32, location.y);
182    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
183    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 2f32, size.width);
184    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 20f32, size.height);
185    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 5f32, location.x);
186    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.y);
187    let Layout { size, location, .. } = taffy.layout(node30).unwrap();
188    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node30.data(), 1f32, size.width);
189    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node30.data(), 10f32, size.height);
190    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node30.data(), 0f32, location.x);
191    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node30.data(), 0f32, location.y);
192    let Layout { size, location, .. } = taffy.layout(node31).unwrap();
193    assert_eq!(size.width, 1f32, "width of node {:?}. Expected {}. Actual {}", node31.data(), 1f32, size.width);
194    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node31.data(), 10f32, size.height);
195    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node31.data(), 0f32, location.x);
196    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node31.data(), 10f32, location.y);
197}