gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 500HTML 254C 19JavaScript 81398 Sutichaykuna

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/flex_shrink_flex_grow_row.rs Rust · 116 siq'ikuna · 4.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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