gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Definiciones

⎇ 0.3.x tests/generated/bevy_issue_9530_reduced.rs Rust · 61 líneas · 3.1 KB Historia Quién tocó qué crudo

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_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
8        .new_leaf_with_measure(
9            taffy::style::Style { flex_grow: 1f32, ..Default::default() },
10            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
11                const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH";
12                super::measure_standard_text(
13                    known_dimensions,
14                    available_space,
15                    TEXT,
16                    super::WritingMode::Horizontal,
17                    None,
18                )
19            }),
20        )
21        .unwrap();
22    let node0 = taffy
23        .new_with_children(
24            taffy::style::Style {
25                flex_direction: taffy::style::FlexDirection::Column,
26                flex_grow: 1f32,
27                ..Default::default()
28            },
29            &[node00],
30        )
31        .unwrap();
32    let node = taffy
33        .new_with_children(
34            taffy::style::Style {
35                flex_direction: taffy::style::FlexDirection::Column,
36                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() },
37                ..Default::default()
38            },
39            &[node0],
40        )
41        .unwrap();
42    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
43    println!("\nComputed tree:");
44    taffy::debug::print_tree(&taffy, node);
45    println!();
46    let Layout { size, location, .. } = taffy.layout(node).unwrap();
47    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.width);
48    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
51    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
52    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
53    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
55    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
56    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
57    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 40f32, size.width);
58    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
61}