gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1347 Definiciones

⎇ 606643cc5fe557da55d348d5f6d38a8791caa24d tests/generated/absolute_child_with_max_height.rs Rust · 65 líneas · 3.3 KB Historia Quién tocó qué crudo

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

1#[test]
2fn absolute_child_with_max_height() {
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(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Points(100f32),
11                height: taffy::style::Dimension::Points(30f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node0 = taffy
17        .new_with_children(
18            taffy::style::Style {
19                position: taffy::style::Position::Absolute,
20                flex_direction: taffy::style::FlexDirection::Column,
21                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(100f32) },
22                inset: taffy::geometry::Rect {
23                    left: auto(),
24                    right: auto(),
25                    top: auto(),
26                    bottom: taffy::style::LengthPercentageAuto::Points(20f32),
27                },
28                ..Default::default()
29            },
30            &[node00],
31        )
32        .unwrap();
33    let node = taffy
34        .new_with_children(
35            taffy::style::Style {
36                flex_direction: taffy::style::FlexDirection::Column,
37                size: taffy::geometry::Size {
38                    width: taffy::style::Dimension::Points(100f32),
39                    height: taffy::style::Dimension::Points(200f32),
40                },
41                ..Default::default()
42            },
43            &[node0],
44        )
45        .unwrap();
46    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
47    println!("\nComputed tree:");
48    taffy::debug::print_tree(&taffy, node);
49    println!();
50    let Layout { size, location, .. } = taffy.layout(node).unwrap();
51    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
52    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
53    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
54    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
55    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
56    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
57    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.height);
58    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
59    assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 150f32, location.y);
60    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
61    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 100f32, size.width);
62    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 30f32, size.height);
63    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
64    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
65}