gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Sutichaykuna

⎇ 0.3.x tests/generated/bevy_issue_10343_flex.rs Rust · 72 siq'ikuna · 4.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

Fix implementation of SizingMode::ContentSize for Flexbox and Grid algorithms (#576) d2b2eb08a · Nico Burns ·

1#[test]
2fn bevy_issue_10343_flex() {
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                display: taffy::style::Display::Flex,
12                size: taffy::geometry::Size {
13                    width: taffy::style::Dimension::Points(200f32),
14                    height: taffy::style::Dimension::Points(200f32),
15                },
16                margin: taffy::geometry::Rect {
17                    left: taffy::style::LengthPercentageAuto::Points(5f32),
18                    right: taffy::style::LengthPercentageAuto::Points(5f32),
19                    top: taffy::style::LengthPercentageAuto::Points(5f32),
20                    bottom: taffy::style::LengthPercentageAuto::Points(5f32),
21                },
22                ..Default::default()
23            },
24            &[node000],
25        )
26        .unwrap();
27    let node0 = taffy
28        .new_with_children(
29            taffy::style::Style { display: taffy::style::Display::Flex, ..Default::default() },
30            &[node00],
31        )
32        .unwrap();
33    let node = taffy
34        .new_with_children(
35            taffy::style::Style {
36                display: taffy::style::Display::Flex,
37                flex_direction: taffy::style::FlexDirection::Column,
38                justify_content: Some(taffy::style::JustifyContent::SpaceAround),
39                size: taffy::geometry::Size {
40                    width: taffy::style::Dimension::Points(100f32),
41                    height: taffy::style::Dimension::Points(100f32),
42                },
43                ..Default::default()
44            },
45            &[node0],
46        )
47        .unwrap();
48    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
49    println!("\nComputed tree:");
50    taffy::debug::print_tree(&taffy, node);
51    println!();
52    let Layout { size, location, .. } = taffy.layout(node).unwrap();
53    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
54    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
57    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
58    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
59    assert_eq!(size.height, 210f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 210f32, size.height);
60    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
61    assert_eq!(location.y, -55f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), -55f32, location.y);
62    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
63    assert_eq!(size.width, 90f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 90f32, size.width);
64    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 200f32, size.height);
65    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 5f32, location.x);
66    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 5f32, location.y);
67    let Layout { size, location, .. } = taffy.layout(node000).unwrap();
68    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, size.width);
69    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node000.data(), 200f32, size.height);
70    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.x);
71    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.y);
72}