gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definitions

⎇ 0.3.x tests/generated/bevy_issue_8017_reduced.rs Rust · 73 lines · 4.3 KB History Who touched what raw

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

1#[test]
2fn bevy_issue_8017_reduced() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node00 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node0 = taffy
9        .new_with_children(
10            taffy::style::Style {
11                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.5f32) },
12                ..Default::default()
13            },
14            &[node00],
15        )
16        .unwrap();
17    let node10 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18    let node1 = taffy
19        .new_with_children(
20            taffy::style::Style {
21                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.5f32) },
22                ..Default::default()
23            },
24            &[node10],
25        )
26        .unwrap();
27    let node = taffy
28        .new_with_children(
29            taffy::style::Style {
30                flex_direction: taffy::style::FlexDirection::Column,
31                gap: taffy::geometry::Size {
32                    width: taffy::style::LengthPercentage::Points(8f32),
33                    height: taffy::style::LengthPercentage::Points(8f32),
34                },
35                size: taffy::geometry::Size {
36                    width: taffy::style::Dimension::Points(200f32),
37                    height: taffy::style::Dimension::Points(400f32),
38                },
39                ..Default::default()
40            },
41            &[node0, node1],
42        )
43        .unwrap();
44    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
45    println!("\nComputed tree:");
46    taffy::debug::print_tree(&taffy, node);
47    println!();
48    let Layout { size, location, .. } = taffy.layout(node).unwrap();
49    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
50    assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.height);
51    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
52    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
53    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
54    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 200f32, size.width);
55    assert_eq!(size.height, 196f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 196f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
58    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
59    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, size.width);
60    assert_eq!(size.height, 196f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 196f32, size.height);
61    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
62    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
63    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
64    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 200f32, size.width);
65    assert_eq!(size.height, 196f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 196f32, size.height);
66    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
67    assert_eq!(location.y, 204f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 204f32, location.y);
68    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
69    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, size.width);
70    assert_eq!(size.height, 196f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 196f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
73}