gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definiciones

⎇ 0.3.x tests/generated/absolute_child_with_cross_margin.rs Rust · 99 líneas · 5.0 KB Historia Quién tocó qué crudo

Import yoga tests (#320) e05b9093d · Nico Burns ·

1#[test]
2fn absolute_child_with_cross_margin() {
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            align_content: Some(taffy::style::AlignContent::Stretch),
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::Points(28f32),
12                height: taffy::style::Dimension::Points(27f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy
18        .new_leaf_with_measure(
19            taffy::style::Style {
20                position: taffy::style::Position::Absolute,
21                align_content: Some(taffy::style::AlignContent::Stretch),
22                flex_grow: 0f32,
23                flex_shrink: 1f32,
24                size: taffy::geometry::Size {
25                    width: taffy::style::Dimension::Percent(1f32),
26                    height: taffy::style::Dimension::Points(15f32),
27                },
28                margin: taffy::geometry::Rect {
29                    left: zero(),
30                    right: zero(),
31                    top: taffy::style::LengthPercentageAuto::Points(4f32),
32                    bottom: zero(),
33                },
34                ..Default::default()
35            },
36            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
37                const TEXT: &str = "\n  ";
38                super::measure_standard_text(
39                    known_dimensions,
40                    available_space,
41                    TEXT,
42                    super::WritingMode::Horizontal,
43                    None,
44                )
45            }),
46        )
47        .unwrap();
48    let node2 = taffy
49        .new_leaf(taffy::style::Style {
50            align_content: Some(taffy::style::AlignContent::Stretch),
51            size: taffy::geometry::Size {
52                width: taffy::style::Dimension::Points(25f32),
53                height: taffy::style::Dimension::Points(27f32),
54            },
55            ..Default::default()
56        })
57        .unwrap();
58    let node = taffy
59        .new_with_children(
60            taffy::style::Style {
61                justify_content: Some(taffy::style::JustifyContent::SpaceBetween),
62                min_size: taffy::geometry::Size {
63                    width: taffy::style::Dimension::Points(311f32),
64                    height: taffy::style::Dimension::Points(0f32),
65                },
66                max_size: taffy::geometry::Size {
67                    width: taffy::style::Dimension::Points(311f32),
68                    height: taffy::style::Dimension::Points(36893500000000000000f32),
69                },
70                ..Default::default()
71            },
72            &[node0, node1, node2],
73        )
74        .unwrap();
75    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
76    println!("\nComputed tree:");
77    taffy::debug::print_tree(&taffy, node);
78    println!();
79    let Layout { size, location, .. } = taffy.layout(node).unwrap();
80    assert_eq!(size.width, 311f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 311f32, size.width);
81    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 27f32, size.height);
82    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
83    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
84    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
85    assert_eq!(size.width, 28f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 28f32, size.width);
86    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 27f32, size.height);
87    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
89    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
90    assert_eq!(size.width, 311f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 311f32, size.width);
91    assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 15f32, size.height);
92    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
93    assert_eq!(location.y, 4f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 4f32, location.y);
94    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
95    assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 25f32, size.width);
96    assert_eq!(size.height, 27f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 27f32, size.height);
97    assert_eq!(location.x, 286f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 286f32, location.x);
98    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
99}