gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Definitions

⎇ 477ff4aff498cbae4cdfbf0cda1ee5b04c784f08 tests/generated/block/block_absolute_aspect_ratio_fill_height.rs Rust · 85 lines · 3.4 KB History Who touched what raw

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn block_absolute_aspect_ratio_fill_height() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            position: taffy::style::Position::Absolute,
9            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
10            aspect_ratio: Some(3f32),
11            inset: taffy::geometry::Rect {
12                left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13                right: auto(),
14                top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
15                bottom: auto(),
16            },
17            ..Default::default()
18        })
19        .unwrap();
20    let node = taffy
21        .new_with_children(
22            taffy::style::Style {
23                display: taffy::style::Display::Block,
24                size: taffy::geometry::Size {
25                    width: taffy::style::Dimension::Length(400f32),
26                    height: taffy::style::Dimension::Length(300f32),
27                },
28                ..Default::default()
29            },
30            &[node0],
31        )
32        .unwrap();
33    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
34    println!("\nComputed tree:");
35    taffy.print_tree(node);
36    println!();
37    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
38    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
39    assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node, 400f32, size.width);
40    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height);
41    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
42    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
43    #[cfg(feature = "content_size")]
44    assert_eq!(
45        layout.scroll_width(),
46        0f32,
47        "scroll_width of node {:?}. Expected {}. Actual {}",
48        node,
49        0f32,
50        layout.scroll_width()
51    );
52    #[cfg(feature = "content_size")]
53    assert_eq!(
54        layout.scroll_height(),
55        0f32,
56        "scroll_height of node {:?}. Expected {}. Actual {}",
57        node,
58        0f32,
59        layout.scroll_height()
60    );
61    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
62    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
63    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
64    assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node0, 67f32, size.height);
65    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0, 20f32, location.x);
66    assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0, 15f32, location.y);
67    #[cfg(feature = "content_size")]
68    assert_eq!(
69        layout.scroll_width(),
70        0f32,
71        "scroll_width of node {:?}. Expected {}. Actual {}",
72        node0,
73        0f32,
74        layout.scroll_width()
75    );
76    #[cfg(feature = "content_size")]
77    assert_eq!(
78        layout.scroll_height(),
79        0f32,
80        "scroll_height of node {:?}. Expected {}. Actual {}",
81        node0,
82        0f32,
83        layout.scroll_height()
84    );
85}