gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1117HTML 1044Markdown 12TOML 94797 Sutichaykuna

⎇ 0.4.x tests/generated/grid/grid_percent_items_width_and_margin.rs Rust · 92 siq'ikuna · 4.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn grid_percent_items_width_and_margin() {
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            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
9            margin: taffy::geometry::Rect {
10                left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
11                right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12                top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13                bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14            },
15            padding: taffy::geometry::Rect {
16                left: taffy::style::LengthPercentage::Length(3f32),
17                right: taffy::style::LengthPercentage::Length(3f32),
18                top: taffy::style::LengthPercentage::Length(3f32),
19                bottom: taffy::style::LengthPercentage::Length(3f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node = taffy
25        .new_with_children(
26            taffy::style::Style {
27                display: taffy::style::Display::Grid,
28                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
29                padding: taffy::geometry::Rect {
30                    left: taffy::style::LengthPercentage::Length(3f32),
31                    right: taffy::style::LengthPercentage::Length(3f32),
32                    top: taffy::style::LengthPercentage::Length(3f32),
33                    bottom: taffy::style::LengthPercentage::Length(3f32),
34                },
35                ..Default::default()
36            },
37            &[node0],
38        )
39        .unwrap();
40    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
41    println!("\nComputed tree:");
42    taffy.print_tree(node);
43    println!();
44    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
45    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
46    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
47    assert_eq!(size.height, 31f32, "height of node {:?}. Expected {}. Actual {}", node, 31f32, size.height);
48    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
49    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
50    #[cfg(feature = "content_size")]
51    assert_eq!(
52        layout.scroll_width(),
53        0f32,
54        "scroll_width of node {:?}. Expected {}. Actual {}",
55        node,
56        0f32,
57        layout.scroll_width()
58    );
59    #[cfg(feature = "content_size")]
60    assert_eq!(
61        layout.scroll_height(),
62        0f32,
63        "scroll_height of node {:?}. Expected {}. Actual {}",
64        node,
65        0f32,
66        layout.scroll_height()
67    );
68    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
69    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
70    assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node0, 87f32, size.width);
71    assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node0, 6f32, size.height);
72    assert_eq!(location.x, 13f32, "x of node {:?}. Expected {}. Actual {}", node0, 13f32, location.x);
73    assert_eq!(location.y, 13f32, "y of node {:?}. Expected {}. Actual {}", node0, 13f32, location.y);
74    #[cfg(feature = "content_size")]
75    assert_eq!(
76        layout.scroll_width(),
77        0f32,
78        "scroll_width of node {:?}. Expected {}. Actual {}",
79        node0,
80        0f32,
81        layout.scroll_width()
82    );
83    #[cfg(feature = "content_size")]
84    assert_eq!(
85        layout.scroll_height(),
86        0f32,
87        "scroll_height of node {:?}. Expected {}. Actual {}",
88        node0,
89        0f32,
90        layout.scroll_height()
91    );
92}