gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

⎇ df4873ec33473556892439341dbc5f9a88ed8808 tests/generated/bevy_issue_9530.rs Rust · 114 lines · 8.6 KB History Who touched what raw

Flexbox: pass correct cross-axis available space when computing an item's intrinsic main size (+misc fixes) (#522) df4873ec3 · Nico Burns ·

1#[test]
2fn bevy_issue_9530() {
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_direction: taffy::style::FlexDirection::Column,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::Percent(1f32),
12                height: taffy::style::Dimension::Points(20f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node10 = taffy
18        .new_leaf(taffy::style::Style {
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::Percent(1f32),
21                height: taffy::style::Dimension::Points(50f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node11 = taffy . new_leaf_with_measure (taffy :: style :: Style { align_items : Some (taffy :: style :: AlignItems :: Center) , align_content : Some (taffy :: style :: AlignContent :: Center) , justify_content : Some (taffy :: style :: JustifyContent :: Center) , flex_grow : 1f32 , margin : taffy :: geometry :: Rect { left : taffy :: style :: LengthPercentageAuto :: Points (20f32) , right : taffy :: style :: LengthPercentageAuto :: Points (20f32) , top : taffy :: style :: LengthPercentageAuto :: Points (20f32) , bottom : taffy :: style :: LengthPercentageAuto :: Points (20f32) , } , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , None) }) ,) . unwrap () ;
27    let node12 = taffy
28        .new_leaf(taffy::style::Style {
29            size: taffy::geometry::Size {
30                width: taffy::style::Dimension::Percent(1f32),
31                height: taffy::style::Dimension::Points(50f32),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node1 = taffy
37        .new_with_children(
38            taffy::style::Style {
39                flex_direction: taffy::style::FlexDirection::Column,
40                flex_grow: 1f32,
41                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
42                margin: taffy::geometry::Rect {
43                    left: taffy::style::LengthPercentageAuto::Points(20f32),
44                    right: taffy::style::LengthPercentageAuto::Points(20f32),
45                    top: taffy::style::LengthPercentageAuto::Points(20f32),
46                    bottom: taffy::style::LengthPercentageAuto::Points(20f32),
47                },
48                padding: taffy::geometry::Rect {
49                    left: taffy::style::LengthPercentage::Points(20f32),
50                    right: taffy::style::LengthPercentage::Points(20f32),
51                    top: taffy::style::LengthPercentage::Points(20f32),
52                    bottom: taffy::style::LengthPercentage::Points(20f32),
53                },
54                ..Default::default()
55            },
56            &[node10, node11, node12],
57        )
58        .unwrap();
59    let node = taffy
60        .new_with_children(
61            taffy::style::Style {
62                flex_direction: taffy::style::FlexDirection::Column,
63                align_items: Some(taffy::style::AlignItems::Center),
64                align_content: Some(taffy::style::AlignContent::Center),
65                size: taffy::geometry::Size {
66                    width: taffy::style::Dimension::Points(300f32),
67                    height: taffy::style::Dimension::Points(300f32),
68                },
69                margin: taffy::geometry::Rect {
70                    left: taffy::style::LengthPercentageAuto::Auto,
71                    right: taffy::style::LengthPercentageAuto::Auto,
72                    top: taffy::style::LengthPercentageAuto::Auto,
73                    bottom: taffy::style::LengthPercentageAuto::Auto,
74                },
75                ..Default::default()
76            },
77            &[node0, node1],
78        )
79        .unwrap();
80    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
81    println!("\nComputed tree:");
82    taffy::debug::print_tree(&taffy, node);
83    println!();
84    let Layout { size, location, .. } = taffy.layout(node).unwrap();
85    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.width);
86    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height);
87    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
89    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
90    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 300f32, size.width);
91    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, size.height);
92    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
93    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
94    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
95    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 300f32, size.width);
96    assert_eq!(size.height, 420f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 420f32, size.height);
97    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
98    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, location.y);
99    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
100    assert_eq!(size.width, 260f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 260f32, size.width);
101    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 50f32, size.height);
102    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 20f32, location.x);
103    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 20f32, location.y);
104    let Layout { size, location, .. } = taffy.layout(node11).unwrap();
105    assert_eq!(size.width, 220f32, "width of node {:?}. Expected {}. Actual {}", node11.data(), 220f32, size.width);
106    assert_eq!(size.height, 240f32, "height of node {:?}. Expected {}. Actual {}", node11.data(), 240f32, size.height);
107    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node11.data(), 40f32, location.x);
108    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node11.data(), 90f32, location.y);
109    let Layout { size, location, .. } = taffy.layout(node12).unwrap();
110    assert_eq!(size.width, 260f32, "width of node {:?}. Expected {}. Actual {}", node12.data(), 260f32, size.width);
111    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node12.data(), 50f32, size.height);
112    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node12.data(), 20f32, location.x);
113    assert_eq!(location.y, 350f32, "y of node {:?}. Expected {}. Actual {}", node12.data(), 350f32, location.y);
114}