gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/align_content_stretch_row_with_single_row.rs Rust · 108 líneas · 4.4 KB Historia Quién tocó qué crudo

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

1#[test]
2fn align_content_stretch_row_with_single_row() {
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(50f32), height: auto() },
9            ..Default::default()
10        })
11        .unwrap();
12    let node1 = taffy
13        .new_leaf(taffy::style::Style {
14            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
15            ..Default::default()
16        })
17        .unwrap();
18    let node = taffy
19        .new_with_children(
20            taffy::style::Style {
21                flex_wrap: taffy::style::FlexWrap::Wrap,
22                align_content: Some(taffy::style::AlignContent::Stretch),
23                size: taffy::geometry::Size {
24                    width: taffy::style::Dimension::Length(150f32),
25                    height: taffy::style::Dimension::Length(100f32),
26                },
27                ..Default::default()
28            },
29            &[node0, node1],
30        )
31        .unwrap();
32    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
33    println!("\nComputed tree:");
34    taffy.print_tree(node);
35    println!();
36    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
37    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
38    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
39    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
40    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
41    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
42    #[cfg(feature = "content_size")]
43    assert_eq!(
44        layout.scroll_width(),
45        0f32,
46        "scroll_width of node {:?}. Expected {}. Actual {}",
47        node,
48        0f32,
49        layout.scroll_width()
50    );
51    #[cfg(feature = "content_size")]
52    assert_eq!(
53        layout.scroll_height(),
54        0f32,
55        "scroll_height of node {:?}. Expected {}. Actual {}",
56        node,
57        0f32,
58        layout.scroll_height()
59    );
60    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
61    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
62    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
63    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
64    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
65    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
66    #[cfg(feature = "content_size")]
67    assert_eq!(
68        layout.scroll_width(),
69        0f32,
70        "scroll_width of node {:?}. Expected {}. Actual {}",
71        node0,
72        0f32,
73        layout.scroll_width()
74    );
75    #[cfg(feature = "content_size")]
76    assert_eq!(
77        layout.scroll_height(),
78        0f32,
79        "scroll_height of node {:?}. Expected {}. Actual {}",
80        node0,
81        0f32,
82        layout.scroll_height()
83    );
84    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
85    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
86    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
87    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
88    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
89    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
90    #[cfg(feature = "content_size")]
91    assert_eq!(
92        layout.scroll_width(),
93        0f32,
94        "scroll_width of node {:?}. Expected {}. Actual {}",
95        node1,
96        0f32,
97        layout.scroll_width()
98    );
99    #[cfg(feature = "content_size")]
100    assert_eq!(
101        layout.scroll_height(),
102        0f32,
103        "scroll_height of node {:?}. Expected {}. Actual {}",
104        node1,
105        0f32,
106        layout.scroll_height()
107    );
108}