gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/gap_column_gap_wrap_align_stretch.rs Rust · 91 líneas · 5.3 KB Historia Quién tocó qué crudo

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

1#[test]
2fn gap_column_gap_wrap_align_stretch() {
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            min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), height: auto() },
11            ..Default::default()
12        })
13        .unwrap();
14    let node1 = taffy
15        .new_leaf(taffy::style::Style {
16            flex_grow: 1f32,
17            min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), height: auto() },
18            ..Default::default()
19        })
20        .unwrap();
21    let node2 = taffy
22        .new_leaf(taffy::style::Style {
23            flex_grow: 1f32,
24            min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), height: auto() },
25            ..Default::default()
26        })
27        .unwrap();
28    let node3 = taffy
29        .new_leaf(taffy::style::Style {
30            flex_grow: 1f32,
31            min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), height: auto() },
32            ..Default::default()
33        })
34        .unwrap();
35    let node4 = taffy
36        .new_leaf(taffy::style::Style {
37            flex_grow: 1f32,
38            min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), height: auto() },
39            ..Default::default()
40        })
41        .unwrap();
42    let node = taffy
43        .new_with_children(
44            taffy::style::Style {
45                flex_wrap: taffy::style::FlexWrap::Wrap,
46                align_content: Some(taffy::style::AlignContent::Stretch),
47                gap: taffy::geometry::Size { width: taffy::style::LengthPercentage::Points(5f32), height: zero() },
48                size: taffy::geometry::Size {
49                    width: taffy::style::Dimension::Points(300f32),
50                    height: taffy::style::Dimension::Points(300f32),
51                },
52                ..Default::default()
53            },
54            &[node0, node1, node2, node3, node4],
55        )
56        .unwrap();
57    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
58    println!("\nComputed tree:");
59    taffy::debug::print_tree(&taffy, node);
60    println!();
61    let Layout { size, location, .. } = taffy.layout(node).unwrap();
62    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.width);
63    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height);
64    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
65    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
66    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
67    assert_eq!(size.width, 71f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 71f32, size.width);
68    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 150f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
71    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
72    assert_eq!(size.width, 72f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 72f32, size.width);
73    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 150f32, size.height);
74    assert_eq!(location.x, 76f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 76f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
76    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
77    assert_eq!(size.width, 71f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 71f32, size.width);
78    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 150f32, size.height);
79    assert_eq!(location.x, 153f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 153f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
81    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
82    assert_eq!(size.width, 71f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 71f32, size.width);
83    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 150f32, size.height);
84    assert_eq!(location.x, 229f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 229f32, location.x);
85    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.y);
86    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
87    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 300f32, size.width);
88    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 150f32, size.height);
89    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 0f32, location.x);
90    assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 150f32, location.y);
91}