gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91822 Sutichaykuna

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/wrapped_row_within_align_items_center.rs Rust · 144 siq'ikuna · 5.7 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn wrapped_row_within_align_items_center() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(150f32),
10                height: taffy::style::Dimension::Length(80f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node01 = taffy
16        .new_leaf(taffy::style::Style {
17            size: taffy::geometry::Size {
18                width: taffy::style::Dimension::Length(80f32),
19                height: taffy::style::Dimension::Length(80f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node0 = taffy
25        .new_with_children(
26            taffy::style::Style { flex_wrap: taffy::style::FlexWrap::Wrap, ..Default::default() },
27            &[node00, node01],
28        )
29        .unwrap();
30    let node = taffy
31        .new_with_children(
32            taffy::style::Style {
33                flex_direction: taffy::style::FlexDirection::Column,
34                align_items: Some(taffy::style::AlignItems::Center),
35                size: taffy::geometry::Size {
36                    width: taffy::style::Dimension::Length(200f32),
37                    height: taffy::style::Dimension::Length(200f32),
38                },
39                ..Default::default()
40            },
41            &[node0],
42        )
43        .unwrap();
44    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
45    println!("\nComputed tree:");
46    taffy.print_tree(node);
47    println!();
48    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
49    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
50    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
51    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
52    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
54    #[cfg(feature = "content_size")]
55    assert_eq!(
56        layout.scroll_width(),
57        0f32,
58        "scroll_width of node {:?}. Expected {}. Actual {}",
59        node,
60        0f32,
61        layout.scroll_width()
62    );
63    #[cfg(feature = "content_size")]
64    assert_eq!(
65        layout.scroll_height(),
66        0f32,
67        "scroll_height of node {:?}. Expected {}. Actual {}",
68        node,
69        0f32,
70        layout.scroll_height()
71    );
72    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
73    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
74    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
75    assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node0, 160f32, size.height);
76    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
77    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
78    #[cfg(feature = "content_size")]
79    assert_eq!(
80        layout.scroll_width(),
81        0f32,
82        "scroll_width of node {:?}. Expected {}. Actual {}",
83        node0,
84        0f32,
85        layout.scroll_width()
86    );
87    #[cfg(feature = "content_size")]
88    assert_eq!(
89        layout.scroll_height(),
90        0f32,
91        "scroll_height of node {:?}. Expected {}. Actual {}",
92        node0,
93        0f32,
94        layout.scroll_height()
95    );
96    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
97    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
98    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node00, 150f32, size.width);
99    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node00, 80f32, size.height);
100    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
101    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
102    #[cfg(feature = "content_size")]
103    assert_eq!(
104        layout.scroll_width(),
105        0f32,
106        "scroll_width of node {:?}. Expected {}. Actual {}",
107        node00,
108        0f32,
109        layout.scroll_width()
110    );
111    #[cfg(feature = "content_size")]
112    assert_eq!(
113        layout.scroll_height(),
114        0f32,
115        "scroll_height of node {:?}. Expected {}. Actual {}",
116        node00,
117        0f32,
118        layout.scroll_height()
119    );
120    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
121    let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
122    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node01, 80f32, size.width);
123    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node01, 80f32, size.height);
124    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
125    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node01, 80f32, location.y);
126    #[cfg(feature = "content_size")]
127    assert_eq!(
128        layout.scroll_width(),
129        0f32,
130        "scroll_width of node {:?}. Expected {}. Actual {}",
131        node01,
132        0f32,
133        layout.scroll_width()
134    );
135    #[cfg(feature = "content_size")]
136    assert_eq!(
137        layout.scroll_height(),
138        0f32,
139        "scroll_height of node {:?}. Expected {}. Actual {}",
140        node01,
141        0f32,
142        layout.scroll_height()
143    );
144}