tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ 859cc921b3adb8e3b184e6fc0cf0c40b6c5a625b tests/generated/gap_column_gap_flexible.rs Rust · 71 lines · 3.7 KB History Who touched what raw

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

1#[test]
2fn gap_column_gap_flexible() {
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            flex_shrink: 1f32,
11            flex_basis: taffy::style::Dimension::Percent(0f32),
12            ..Default::default()
13        })
14        .unwrap();
15    let node1 = taffy
16        .new_leaf(taffy::style::Style {
17            flex_grow: 1f32,
18            flex_shrink: 1f32,
19            flex_basis: taffy::style::Dimension::Percent(0f32),
20            ..Default::default()
21        })
22        .unwrap();
23    let node2 = taffy
24        .new_leaf(taffy::style::Style {
25            flex_grow: 1f32,
26            flex_shrink: 1f32,
27            flex_basis: taffy::style::Dimension::Percent(0f32),
28            ..Default::default()
29        })
30        .unwrap();
31    let node = taffy
32        .new_with_children(
33            taffy::style::Style {
34                gap: taffy::geometry::Size {
35                    width: taffy::style::LengthPercentage::Points(10f32),
36                    height: taffy::style::LengthPercentage::Points(20f32),
37                },
38                size: taffy::geometry::Size {
39                    width: taffy::style::Dimension::Points(80f32),
40                    height: taffy::style::Dimension::Points(100f32),
41                },
42                ..Default::default()
43            },
44            &[node0, node1, node2],
45        )
46        .unwrap();
47    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
48    println!("\nComputed tree:");
49    taffy::debug::print_tree(&taffy, node);
50    println!();
51    let Layout { size, location, .. } = taffy.layout(node).unwrap();
52    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 80f32, size.width);
53    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
55    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
56    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
57    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
58    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
61    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
62    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.width);
63    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, size.height);
64    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 30f32, location.x);
65    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
66    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
67    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.width);
68    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, size.height);
69    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 60f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
71}