tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91841 Definiciones

⎇ df4873ec33473556892439341dbc5f9a88ed8808 tests/generated/bevy_issue_9530_reduced2.rs Rust · 64 líneas · 3.4 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_reduced2() {
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\u{200b}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                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(80f32), height: auto() },
28                margin: taffy::geometry::Rect {
29                    left: taffy::style::LengthPercentageAuto::Points(20f32),
30                    right: taffy::style::LengthPercentageAuto::Points(20f32),
31                    top: taffy::style::LengthPercentageAuto::Points(0f32),
32                    bottom: taffy::style::LengthPercentageAuto::Points(0f32),
33                },
34                ..Default::default()
35            },
36            &[node00],
37        )
38        .unwrap();
39    let node = taffy
40        .new_with_children(
41            taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, ..Default::default() },
42            &[node0],
43        )
44        .unwrap();
45    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
46    println!("\nComputed tree:");
47    taffy::debug::print_tree(&taffy, node);
48    println!();
49    let Layout { size, location, .. } = taffy.layout(node).unwrap();
50    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.width);
51    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.height);
52    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
54    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
55    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width);
56    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
57    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, location.x);
58    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
59    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
60    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 80f32, size.width);
61    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.height);
62    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
63    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
64}