gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Sutichaykuna

⎇ c154b8aa719da0d6f8636b123765a47fa40a3306 tests/generated/flex/absolute_layout_width_height_end_bottom.rs Rust · 86 siq'ikuna · 3.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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