gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Sutichaykuna

⎇ 0.5.x tests/generated/flex/absolute_layout_no_size.rs Rust · 73 siq'ikuna · 2.9 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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