gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Definitions

⎇ 01babab32d8138f3c3fa05095fb6c65fca0d3967 tests/generated/grid_justify_items_sized_center.rs Rust · 76 lines · 3.9 KB History Who touched what raw

Better assert messages (#290) 2b7d63a03 · Nico Burns ·

1#[test]
2fn grid_justify_items_sized_center() {
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_row: taffy::geometry::Line {
10                start: taffy::style::GridPlacement::Line(1i16),
11                end: taffy::style::GridPlacement::Auto,
12            },
13            grid_column: taffy::geometry::Line {
14                start: taffy::style::GridPlacement::Line(1i16),
15                end: taffy::style::GridPlacement::Auto,
16            },
17            size: taffy::geometry::Size {
18                width: taffy::style::Dimension::Points(20f32),
19                height: taffy::style::Dimension::Points(20f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node1 = taffy
25        .new_leaf(taffy::style::Style {
26            grid_row: taffy::geometry::Line {
27                start: taffy::style::GridPlacement::Line(3i16),
28                end: taffy::style::GridPlacement::Auto,
29            },
30            grid_column: taffy::geometry::Line {
31                start: taffy::style::GridPlacement::Line(3i16),
32                end: taffy::style::GridPlacement::Auto,
33            },
34            size: taffy::geometry::Size {
35                width: taffy::style::Dimension::Points(60f32),
36                height: taffy::style::Dimension::Points(60f32),
37            },
38            ..Default::default()
39        })
40        .unwrap();
41    let node = taffy
42        .new_with_children(
43            taffy::style::Style {
44                display: taffy::style::Display::Grid,
45                justify_items: Some(taffy::style::JustifyItems::Center),
46                grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
47                grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
48                size: taffy::geometry::Size {
49                    width: taffy::style::Dimension::Points(120f32),
50                    height: taffy::style::Dimension::Points(120f32),
51                },
52                ..Default::default()
53            },
54            &[node0, node1],
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, 120f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.width);
63    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 120f32, 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, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
68    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
69    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, 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, 60f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.width);
73    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.height);
74    assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 70f32, location.x);
75    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 80f32, location.y);
76}