tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 245JavaScript 8Markdown 71218 Definiciones

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/grid_percent_items_nested_moderate.rs Rust · 113 líneas · 4.9 KB Historia Quién tocó qué crudo

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

1#[test]
2fn grid_percent_items_nested_moderate() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    taffy.disable_rounding();
8    let node00 = taffy
9        .new_leaf(taffy::style::Style {
10            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
11            margin: taffy::geometry::Rect {
12                left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13                right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14                top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
15                bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
16            },
17            padding: taffy::geometry::Rect {
18                left: taffy::style::LengthPercentage::Points(3f32),
19                right: taffy::style::LengthPercentage::Points(3f32),
20                top: taffy::style::LengthPercentage::Points(3f32),
21                bottom: taffy::style::LengthPercentage::Points(3f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node0 = taffy
27        .new_with_children(
28            taffy::style::Style {
29                display: taffy::style::Display::Grid,
30                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
31                margin: taffy::geometry::Rect {
32                    left: taffy::style::LengthPercentageAuto::Points(5f32),
33                    right: taffy::style::LengthPercentageAuto::Points(5f32),
34                    top: taffy::style::LengthPercentageAuto::Points(5f32),
35                    bottom: taffy::style::LengthPercentageAuto::Points(5f32),
36                },
37                padding: taffy::geometry::Rect {
38                    left: taffy::style::LengthPercentage::Percent(0.03f32),
39                    right: taffy::style::LengthPercentage::Percent(0.03f32),
40                    top: taffy::style::LengthPercentage::Percent(0.03f32),
41                    bottom: taffy::style::LengthPercentage::Percent(0.03f32),
42                },
43                ..Default::default()
44            },
45            &[node00],
46        )
47        .unwrap();
48    let node = taffy
49        .new_with_children(
50            taffy::style::Style {
51                display: taffy::style::Display::Grid,
52                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
53                padding: taffy::geometry::Rect {
54                    left: taffy::style::LengthPercentage::Points(3f32),
55                    right: taffy::style::LengthPercentage::Points(3f32),
56                    top: taffy::style::LengthPercentage::Points(3f32),
57                    bottom: taffy::style::LengthPercentage::Points(3f32),
58                },
59                ..Default::default()
60            },
61            &[node0],
62        )
63        .unwrap();
64    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
65    println!("\nComputed tree:");
66    taffy::debug::print_tree(&taffy, node);
67    println!();
68    let Layout { size, location, .. } = taffy.layout(node).unwrap();
69    assert!(size.width - 200f32 < 0.1, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
70    assert!(
71        size.height - 42.15625f32 < 0.1,
72        "height of node {:?}. Expected {}. Actual {}",
73        node.data(),
74        42.15625f32,
75        size.height
76    );
77    assert!(location.x - 0f32 < 0.1, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
78    assert!(location.y - 0f32 < 0.1, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
79    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
80    assert!(size.width - 97f32 < 0.1, "width of node {:?}. Expected {}. Actual {}", node0.data(), 97f32, size.width);
81    assert!(
82        size.height - 26.15625f32 < 0.1,
83        "height of node {:?}. Expected {}. Actual {}",
84        node0.data(),
85        26.15625f32,
86        size.height
87    );
88    assert!(location.x - 8f32 < 0.1, "x of node {:?}. Expected {}. Actual {}", node0.data(), 8f32, location.x);
89    assert!(location.y - 8f32 < 0.1, "y of node {:?}. Expected {}. Actual {}", node0.data(), 8f32, location.y);
90    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
91    assert!(
92        size.width - 38.414063f32 < 0.1,
93        "width of node {:?}. Expected {}. Actual {}",
94        node00.data(),
95        38.414063f32,
96        size.width
97    );
98    assert!(size.height - 6f32 < 0.1, "height of node {:?}. Expected {}. Actual {}", node00.data(), 6f32, size.height);
99    assert!(
100        location.x - 10.078125f32 < 0.1,
101        "x of node {:?}. Expected {}. Actual {}",
102        node00.data(),
103        10.078125f32,
104        location.x
105    );
106    assert!(
107        location.y - 10.078125f32 < 0.1,
108        "y of node {:?}. Expected {}. Actual {}",
109        node00.data(),
110        10.078125f32,
111        location.y
112    );
113}