tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Definitions

⎇ 0.3.x tests/generated/bevy_issue_7976_4_level.rs Rust · 87 lines · 4.7 KB History Who touched what raw

Update 0.3.x for 0.3.11 (#455) 1cc940684 · Nico Burns ·

1#[test]
2fn bevy_issue_7976_4_level() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node000 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node00 = taffy
9        .new_with_children(
10            taffy::style::Style {
11                size: taffy::geometry::Size {
12                    width: taffy::style::Dimension::Percent(1f32),
13                    height: taffy::style::Dimension::Percent(1f32),
14                },
15                padding: taffy::geometry::Rect {
16                    left: taffy::style::LengthPercentage::Points(5f32),
17                    right: taffy::style::LengthPercentage::Points(5f32),
18                    top: taffy::style::LengthPercentage::Points(5f32),
19                    bottom: taffy::style::LengthPercentage::Points(5f32),
20                },
21                ..Default::default()
22            },
23            &[node000],
24        )
25        .unwrap();
26    let node0 = taffy
27        .new_with_children(
28            taffy::style::Style {
29                min_size: taffy::geometry::Size {
30                    width: taffy::style::Dimension::Points(40f32),
31                    height: taffy::style::Dimension::Points(40f32),
32                },
33                margin: taffy::geometry::Rect {
34                    left: taffy::style::LengthPercentageAuto::Points(5f32),
35                    right: taffy::style::LengthPercentageAuto::Points(5f32),
36                    top: taffy::style::LengthPercentageAuto::Points(5f32),
37                    bottom: taffy::style::LengthPercentageAuto::Points(5f32),
38                },
39                padding: taffy::geometry::Rect {
40                    left: taffy::style::LengthPercentage::Points(5f32),
41                    right: taffy::style::LengthPercentage::Points(5f32),
42                    top: taffy::style::LengthPercentage::Points(5f32),
43                    bottom: taffy::style::LengthPercentage::Points(5f32),
44                },
45                ..Default::default()
46            },
47            &[node00],
48        )
49        .unwrap();
50    let node = taffy
51        .new_with_children(
52            taffy::style::Style {
53                align_content: Some(taffy::style::AlignContent::Start),
54                size: taffy::geometry::Size {
55                    width: taffy::style::Dimension::Points(200f32),
56                    height: taffy::style::Dimension::Points(200f32),
57                },
58                ..Default::default()
59            },
60            &[node0],
61        )
62        .unwrap();
63    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
64    println!("\nComputed tree:");
65    taffy::debug::print_tree(&taffy, node);
66    println!();
67    let Layout { size, location, .. } = taffy.layout(node).unwrap();
68    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
69    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
70    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
71    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
72    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
73    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
74    assert_eq!(size.height, 190f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 190f32, size.height);
75    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 5f32, location.x);
76    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 5f32, location.y);
77    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
78    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 30f32, size.width);
79    assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 180f32, size.height);
80    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 5f32, location.x);
81    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 5f32, location.y);
82    let Layout { size, location, .. } = taffy.layout(node000).unwrap();
83    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, size.width);
84    assert_eq!(size.height, 170f32, "height of node {:?}. Expected {}. Actual {}", node000.data(), 170f32, size.height);
85    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node000.data(), 5f32, location.x);
86    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node000.data(), 5f32, location.y);
87}