gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/flex_grow_height_maximized.rs Rust · 144 líneas · 5.8 KB Historia Quién tocó qué crudo

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

1#[test]
2fn flex_grow_height_maximized() {
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            flex_grow: 1f32,
9            flex_basis: taffy::style::Dimension::Length(200f32),
10            ..Default::default()
11        })
12        .unwrap();
13    let node01 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
16            ..Default::default()
17        })
18        .unwrap();
19    let node0 = taffy
20        .new_with_children(
21            taffy::style::Style {
22                flex_direction: taffy::style::FlexDirection::Column,
23                flex_grow: 1f32,
24                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
25                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(500f32) },
26                ..Default::default()
27            },
28            &[node00, node01],
29        )
30        .unwrap();
31    let node = taffy
32        .new_with_children(
33            taffy::style::Style {
34                flex_direction: taffy::style::FlexDirection::Column,
35                size: taffy::geometry::Size {
36                    width: taffy::style::Dimension::Length(100f32),
37                    height: taffy::style::Dimension::Length(500f32),
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
51    assert_eq!(size.height, 500f32, "height of node {:?}. Expected {}. Actual {}", node, 500f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
75    assert_eq!(size.height, 500f32, "height of node {:?}. Expected {}. Actual {}", node0, 500f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
99    assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node00, 400f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node01, 100f32, size.width);
123    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node01, 100f32, size.height);
124    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
125    assert_eq!(location.y, 400f32, "y of node {:?}. Expected {}. Actual {}", node01, 400f32, 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}