gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Sutichaykuna

⎇ 65bedf128ec8cef40c1a21b6f141f2c771842cca tests/generated/flex/gap_column_gap_start_index.rs Rust · 86 siq'ikuna · 4.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

Add test for gap when the first child is position:absolute (#542) 65bedf128 · Nico Burns ·

1#[test]
2fn gap_column_gap_start_index() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            position: taffy::style::Position::Absolute,
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(20f32),
11                height: taffy::style::Dimension::Length(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::Length(20f32),
20                height: taffy::style::Dimension::Length(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::Length(20f32),
29                height: taffy::style::Dimension::Length(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::Length(20f32),
38                height: taffy::style::Dimension::Length(20f32),
39            },
40            ..Default::default()
41        })
42        .unwrap();
43    let node = taffy
44        .new_with_children(
45            taffy::style::Style {
46                flex_wrap: taffy::style::FlexWrap::Wrap,
47                gap: taffy::geometry::Size {
48                    width: taffy::style::LengthPercentage::Length(10f32),
49                    height: taffy::style::LengthPercentage::Length(20f32),
50                },
51                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(80f32), height: auto() },
52                ..Default::default()
53            },
54            &[node0, node1, node2, node3],
55        )
56        .unwrap();
57    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
58    println!("\nComputed tree:");
59    taffy::util::print_tree(&taffy, node);
60    println!();
61    let Layout { size, location, .. } = taffy.layout(node).unwrap();
62    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
63    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
64    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
65    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
66    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
67    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
68    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
71    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
72    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
73    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
74    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
76    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
77    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
78    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
79    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node2, 30f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
81    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
82    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
83    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
84    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node3, 60f32, location.x);
85    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
86}