tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 496HTML 245JavaScript 8CSS 61214 Definiciones

⎇ morphorm tests/generated/grid/grid_percent_items_nested_moderate.rs Rust · 112 líneas · 4.9 KB Historia Quién tocó qué crudo

Replace per-node measure functions with a single measure function + per-node context (#490) be627e7fa · Nico Burns ·

1#[test]
2fn grid_percent_items_nested_moderate() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, Taffy};
5    let mut taffy: Taffy<crate::TextMeasure> = Taffy::new();
6    taffy.disable_rounding();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
10            margin: taffy::geometry::Rect {
11                left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12                right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13                top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14                bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
15            },
16            padding: taffy::geometry::Rect {
17                left: taffy::style::LengthPercentage::Length(3f32),
18                right: taffy::style::LengthPercentage::Length(3f32),
19                top: taffy::style::LengthPercentage::Length(3f32),
20                bottom: taffy::style::LengthPercentage::Length(3f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node0 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                display: taffy::style::Display::Grid,
29                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
30                margin: taffy::geometry::Rect {
31                    left: taffy::style::LengthPercentageAuto::Length(5f32),
32                    right: taffy::style::LengthPercentageAuto::Length(5f32),
33                    top: taffy::style::LengthPercentageAuto::Length(5f32),
34                    bottom: taffy::style::LengthPercentageAuto::Length(5f32),
35                },
36                padding: taffy::geometry::Rect {
37                    left: taffy::style::LengthPercentage::Percent(0.03f32),
38                    right: taffy::style::LengthPercentage::Percent(0.03f32),
39                    top: taffy::style::LengthPercentage::Percent(0.03f32),
40                    bottom: taffy::style::LengthPercentage::Percent(0.03f32),
41                },
42                ..Default::default()
43            },
44            &[node00],
45        )
46        .unwrap();
47    let node = taffy
48        .new_with_children(
49            taffy::style::Style {
50                display: taffy::style::Display::Grid,
51                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
52                padding: taffy::geometry::Rect {
53                    left: taffy::style::LengthPercentage::Length(3f32),
54                    right: taffy::style::LengthPercentage::Length(3f32),
55                    top: taffy::style::LengthPercentage::Length(3f32),
56                    bottom: taffy::style::LengthPercentage::Length(3f32),
57                },
58                ..Default::default()
59            },
60            &[node0],
61        )
62        .unwrap();
63    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
64    println!("\nComputed tree:");
65    taffy.print_tree(node);
66    println!();
67    let Layout { size, location, .. } = taffy.layout(node).unwrap();
68    assert!(size.width - 200f32 < 0.1, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
69    assert!(
70        size.height - 42.15625f32 < 0.1,
71        "height of node {:?}. Expected {}. Actual {}",
72        node,
73        42.15625f32,
74        size.height
75    );
76    assert!(location.x - 0f32 < 0.1, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
77    assert!(location.y - 0f32 < 0.1, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
78    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
79    assert!(size.width - 97f32 < 0.1, "width of node {:?}. Expected {}. Actual {}", node0, 97f32, size.width);
80    assert!(
81        size.height - 26.15625f32 < 0.1,
82        "height of node {:?}. Expected {}. Actual {}",
83        node0,
84        26.15625f32,
85        size.height
86    );
87    assert!(location.x - 8f32 < 0.1, "x of node {:?}. Expected {}. Actual {}", node0, 8f32, location.x);
88    assert!(location.y - 8f32 < 0.1, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
89    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
90    assert!(
91        size.width - 38.414063f32 < 0.1,
92        "width of node {:?}. Expected {}. Actual {}",
93        node00,
94        38.414063f32,
95        size.width
96    );
97    assert!(size.height - 6f32 < 0.1, "height of node {:?}. Expected {}. Actual {}", node00, 6f32, size.height);
98    assert!(
99        location.x - 10.078125f32 < 0.1,
100        "x of node {:?}. Expected {}. Actual {}",
101        node00,
102        10.078125f32,
103        location.x
104    );
105    assert!(
106        location.y - 10.078125f32 < 0.1,
107        "y of node {:?}. Expected {}. Actual {}",
108        node00,
109        10.078125f32,
110        location.y
111    );
112}