gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/rounding_fractial_input_6.rs Rust · 111 lines · 6.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_6() {
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(2f32),
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(2f32),
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.5f32), 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(2f32),
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(2f32),
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.5f32), height: auto() },
58                ..Default::default()
59            },
60            &[node10, node11],
61        )
62        .unwrap();
63    let node = taffy
64        .new_with_children(
65            taffy::style::Style {
66                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(7f32), height: auto() },
67                ..Default::default()
68            },
69            &[node0, node1],
70        )
71        .unwrap();
72    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
73    println!("\nComputed tree:");
74    taffy::debug::print_tree(&taffy, node);
75    println!();
76    let Layout { size, location, .. } = taffy.layout(node).unwrap();
77    assert_eq!(size.width, 7f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 7f32, size.width);
78    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.height);
79    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
81    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
82    assert_eq!(size.width, 4f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 4f32, size.width);
83    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
84    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
85    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
86    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
87    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 2f32, size.width);
88    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, size.height);
89    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
90    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
91    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
92    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 2f32, size.width);
93    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 10f32, size.height);
94    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.x);
95    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 10f32, location.y);
96    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
97    assert_eq!(size.width, 3f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 3f32, size.width);
98    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
99    assert_eq!(location.x, 4f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 4f32, location.x);
100    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
101    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
102    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 2f32, size.width);
103    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 10f32, size.height);
104    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
105    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
106    let Layout { size, location, .. } = taffy.layout(node11).unwrap();
107    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node11.data(), 2f32, size.width);
108    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node11.data(), 10f32, size.height);
109    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node11.data(), 0f32, location.x);
110    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node11.data(), 10f32, location.y);
111}