gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Definitions

⎇ 0.3.x tests/generated/grid_auto_columns.rs Rust · 82 lines · 6.3 KB History Who touched what raw

Fix CSS Grid "auto track" / placement bugs (#481) a74aeab0d · Nico Burns ·

1#[test]
2fn grid_auto_columns() {
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            grid_column: taffy::geometry::Line { start: line(-3i16), end: taffy::style::GridPlacement::Auto },
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
14    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
15    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
16    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
17    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18    let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19    let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20    let node = taffy
21        .new_with_children(
22            taffy::style::Style {
23                display: taffy::style::Display::Grid,
24                grid_template_rows: vec![points(100f32)],
25                grid_template_columns: vec![points(40f32)],
26                grid_auto_columns: vec![points(10f32), points(20f32), points(30f32)],
27                grid_auto_flow: taffy::style::GridAutoFlow::Column,
28                ..Default::default()
29            },
30            &[node0, node1, node2, node3, node4, node5, node6, node7],
31        )
32        .unwrap();
33    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
34    println!("\nComputed tree:");
35    taffy::debug::print_tree(&taffy, node);
36    println!();
37    let Layout { size, location, .. } = taffy.layout(node).unwrap();
38    assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 190f32, size.width);
39    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
40    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
41    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
42    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
43    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.width);
44    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height);
45    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
46    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
47    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
48    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.width);
49    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, size.height);
50    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
52    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
53    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 10f32, size.width);
54    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, size.height);
55    assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 70f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
57    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
58    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 20f32, size.width);
59    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 100f32, size.height);
60    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 80f32, location.x);
61    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 0f32, location.y);
62    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
63    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node4.data(), 30f32, size.width);
64    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node4.data(), 100f32, size.height);
65    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node4.data(), 100f32, location.x);
66    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4.data(), 0f32, location.y);
67    let Layout { size, location, .. } = taffy.layout(node5).unwrap();
68    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node5.data(), 10f32, size.width);
69    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node5.data(), 100f32, size.height);
70    assert_eq!(location.x, 130f32, "x of node {:?}. Expected {}. Actual {}", node5.data(), 130f32, location.x);
71    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node5.data(), 0f32, location.y);
72    let Layout { size, location, .. } = taffy.layout(node6).unwrap();
73    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6.data(), 20f32, size.width);
74    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node6.data(), 100f32, size.height);
75    assert_eq!(location.x, 140f32, "x of node {:?}. Expected {}. Actual {}", node6.data(), 140f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node6.data(), 0f32, location.y);
77    let Layout { size, location, .. } = taffy.layout(node7).unwrap();
78    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node7.data(), 30f32, size.width);
79    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node7.data(), 100f32, size.height);
80    assert_eq!(location.x, 160f32, "x of node {:?}. Expected {}. Actual {}", node7.data(), 160f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node7.data(), 0f32, location.y);
82}