gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 701HTML 654Markdown 12TOML 62332 Definiciones

⎇ c154b8aa719da0d6f8636b123765a47fa40a3306 tests/generated/flex/margin_auto_top_stretching_child.rs Rust · 118 líneas · 4.6 KB Historia Quién tocó qué crudo

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

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