gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definiciones

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/gap_column_gap_wrap_align_flex_start.rs Rust · 118 líneas · 6.5 KB Historia Quién tocó qué crudo

Reinstate FlexStart and FlexEnd alignment variants (#336) 78fd9cc09 · Nico Burns ·

1#[test]
2fn gap_column_gap_wrap_align_flex_start() {
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            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Points(20f32),
11                height: taffy::style::Dimension::Points(20f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node1 = taffy
17        .new_leaf(taffy::style::Style {
18            size: taffy::geometry::Size {
19                width: taffy::style::Dimension::Points(20f32),
20                height: taffy::style::Dimension::Points(20f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node2 = taffy
26        .new_leaf(taffy::style::Style {
27            size: taffy::geometry::Size {
28                width: taffy::style::Dimension::Points(20f32),
29                height: taffy::style::Dimension::Points(20f32),
30            },
31            ..Default::default()
32        })
33        .unwrap();
34    let node3 = taffy
35        .new_leaf(taffy::style::Style {
36            size: taffy::geometry::Size {
37                width: taffy::style::Dimension::Points(20f32),
38                height: taffy::style::Dimension::Points(20f32),
39            },
40            ..Default::default()
41        })
42        .unwrap();
43    let node4 = taffy
44        .new_leaf(taffy::style::Style {
45            size: taffy::geometry::Size {
46                width: taffy::style::Dimension::Points(20f32),
47                height: taffy::style::Dimension::Points(20f32),
48            },
49            ..Default::default()
50        })
51        .unwrap();
52    let node5 = taffy
53        .new_leaf(taffy::style::Style {
54            size: taffy::geometry::Size {
55                width: taffy::style::Dimension::Points(20f32),
56                height: taffy::style::Dimension::Points(20f32),
57            },
58            ..Default::default()
59        })
60        .unwrap();
61    let node = taffy
62        .new_with_children(
63            taffy::style::Style {
64                flex_wrap: taffy::style::FlexWrap::Wrap,
65                align_content: Some(taffy::style::AlignContent::FlexStart),
66                gap: taffy::geometry::Size {
67                    width: taffy::style::LengthPercentage::Points(10f32),
68                    height: taffy::style::LengthPercentage::Points(20f32),
69                },
70                size: taffy::geometry::Size {
71                    width: taffy::style::Dimension::Points(100f32),
72                    height: taffy::style::Dimension::Points(100f32),
73                },
74                ..Default::default()
75            },
76            &[node0, node1, node2, node3, node4, node5],
77        )
78        .unwrap();
79    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
80    println!("\nComputed tree:");
81    taffy::debug::print_tree(&taffy, node);
82    println!();
83    let Layout { size, location, .. } = taffy.layout(node).unwrap();
84    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
85    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
86    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
87    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
88    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
89    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
90    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
91    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
92    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
93    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
94    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.width);
95    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
96    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, location.x);
97    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
98    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
99    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.width);
100    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.height);
101    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 60f32, location.x);
102    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
103    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
104    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 20f32, size.width);
105    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 20f32, size.height);
106    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.x);
107    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 40f32, location.y);
108    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
109    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.width);
110    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 20f32, size.height);
111    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 30f32, location.x);
112    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 40f32, location.y);
113    let Layout { size, location, .. } = taffy.layout(node5).unwrap();
114    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node5.data(), 20f32, size.width);
115    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node5.data(), 20f32, size.height);
116    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node5.data(), 60f32, location.x);
117    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node5.data(), 40f32, location.y);
118}