gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

⎇ 0.3.x tests/generated/rounding_inner_node_controversy_combined.rs Rust · 120 líneas · 6.9 KB Historia Quién tocó qué crudo

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

1#[test]
2fn rounding_inner_node_controversy_combined() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_grow: 1f32,
10            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(1f32) },
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::Percent(1f32), height: auto() },
18            ..Default::default()
19        })
20        .unwrap();
21    let node110 = taffy
22        .new_leaf(taffy::style::Style {
23            flex_grow: 1f32,
24            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
25            ..Default::default()
26        })
27        .unwrap();
28    let node11 = taffy
29        .new_with_children(
30            taffy::style::Style {
31                flex_direction: taffy::style::FlexDirection::Column,
32                flex_grow: 1f32,
33                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
34                ..Default::default()
35            },
36            &[node110],
37        )
38        .unwrap();
39    let node12 = taffy
40        .new_leaf(taffy::style::Style {
41            flex_grow: 1f32,
42            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
43            ..Default::default()
44        })
45        .unwrap();
46    let node1 = taffy
47        .new_with_children(
48            taffy::style::Style {
49                flex_direction: taffy::style::FlexDirection::Column,
50                flex_grow: 1f32,
51                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(1f32) },
52                ..Default::default()
53            },
54            &[node10, node11, node12],
55        )
56        .unwrap();
57    let node2 = taffy
58        .new_leaf(taffy::style::Style {
59            flex_grow: 1f32,
60            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(1f32) },
61            ..Default::default()
62        })
63        .unwrap();
64    let node = taffy
65        .new_with_children(
66            taffy::style::Style {
67                size: taffy::geometry::Size {
68                    width: taffy::style::Dimension::Points(640f32),
69                    height: taffy::style::Dimension::Points(320f32),
70                },
71                ..Default::default()
72            },
73            &[node0, node1, node2],
74        )
75        .unwrap();
76    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
77    println!("\nComputed tree:");
78    taffy::debug::print_tree(&taffy, node);
79    println!();
80    let Layout { size, location, .. } = taffy.layout(node).unwrap();
81    assert_eq!(size.width, 640f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 640f32, size.width);
82    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 320f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
84    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
85    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
86    assert_eq!(size.width, 213f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 213f32, size.width);
87    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 320f32, size.height);
88    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
89    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
90    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
91    assert_eq!(size.width, 214f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 214f32, size.width);
92    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 320f32, size.height);
93    assert_eq!(location.x, 213f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 213f32, location.x);
94    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
95    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
96    assert_eq!(size.width, 214f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 214f32, size.width);
97    assert_eq!(size.height, 107f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 107f32, size.height);
98    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
99    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
100    let Layout { size, location, .. } = taffy.layout(node11).unwrap();
101    assert_eq!(size.width, 214f32, "width of node {:?}. Expected {}. Actual {}", node11.data(), 214f32, size.width);
102    assert_eq!(size.height, 106f32, "height of node {:?}. Expected {}. Actual {}", node11.data(), 106f32, size.height);
103    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node11.data(), 0f32, location.x);
104    assert_eq!(location.y, 107f32, "y of node {:?}. Expected {}. Actual {}", node11.data(), 107f32, location.y);
105    let Layout { size, location, .. } = taffy.layout(node110).unwrap();
106    assert_eq!(size.width, 214f32, "width of node {:?}. Expected {}. Actual {}", node110.data(), 214f32, size.width);
107    assert_eq!(size.height, 106f32, "height of node {:?}. Expected {}. Actual {}", node110.data(), 106f32, size.height);
108    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node110.data(), 0f32, location.x);
109    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node110.data(), 0f32, location.y);
110    let Layout { size, location, .. } = taffy.layout(node12).unwrap();
111    assert_eq!(size.width, 214f32, "width of node {:?}. Expected {}. Actual {}", node12.data(), 214f32, size.width);
112    assert_eq!(size.height, 107f32, "height of node {:?}. Expected {}. Actual {}", node12.data(), 107f32, size.height);
113    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node12.data(), 0f32, location.x);
114    assert_eq!(location.y, 213f32, "y of node {:?}. Expected {}. Actual {}", node12.data(), 213f32, location.y);
115    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
116    assert_eq!(size.width, 213f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 213f32, size.width);
117    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 320f32, size.height);
118    assert_eq!(location.x, 427f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 427f32, location.x);
119    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
120}