gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94520 Definitions

⎇ 0.5.x tests/generated/flex/align_items_stretch.rs Rust · 76 lines · 3.0 KB History Who touched what raw

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

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