gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/flex_grow_root_minimized.rs Rust · 143 líneas · 6.0 KB Historia Quién tocó qué crudo

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

1#[test]
2fn flex_grow_root_minimized() {
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 { width: taffy::style::Dimension::Length(100f32), height: auto() },
36                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
37                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(500f32) },
38                ..Default::default()
39            },
40            &[node0],
41        )
42        .unwrap();
43    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
44    println!("\nComputed tree:");
45    taffy.print_tree(node);
46    println!();
47    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
48    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
49    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
50    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height);
51    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
52    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
53    #[cfg(feature = "content_size")]
54    assert_eq!(
55        layout.scroll_width(),
56        0f32,
57        "scroll_width of node {:?}. Expected {}. Actual {}",
58        node,
59        0f32,
60        layout.scroll_width()
61    );
62    #[cfg(feature = "content_size")]
63    assert_eq!(
64        layout.scroll_height(),
65        0f32,
66        "scroll_height of node {:?}. Expected {}. Actual {}",
67        node,
68        0f32,
69        layout.scroll_height()
70    );
71    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
72    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
73    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
74    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node0, 300f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
77    #[cfg(feature = "content_size")]
78    assert_eq!(
79        layout.scroll_width(),
80        0f32,
81        "scroll_width of node {:?}. Expected {}. Actual {}",
82        node0,
83        0f32,
84        layout.scroll_width()
85    );
86    #[cfg(feature = "content_size")]
87    assert_eq!(
88        layout.scroll_height(),
89        0f32,
90        "scroll_height of node {:?}. Expected {}. Actual {}",
91        node0,
92        0f32,
93        layout.scroll_height()
94    );
95    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
96    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
97    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
98    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00, 200f32, size.height);
99    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
100    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
101    #[cfg(feature = "content_size")]
102    assert_eq!(
103        layout.scroll_width(),
104        0f32,
105        "scroll_width of node {:?}. Expected {}. Actual {}",
106        node00,
107        0f32,
108        layout.scroll_width()
109    );
110    #[cfg(feature = "content_size")]
111    assert_eq!(
112        layout.scroll_height(),
113        0f32,
114        "scroll_height of node {:?}. Expected {}. Actual {}",
115        node00,
116        0f32,
117        layout.scroll_height()
118    );
119    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
120    let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
121    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node01, 100f32, size.width);
122    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node01, 100f32, size.height);
123    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01, 0f32, location.x);
124    assert_eq!(location.y, 200f32, "y of node {:?}. Expected {}. Actual {}", node01, 200f32, location.y);
125    #[cfg(feature = "content_size")]
126    assert_eq!(
127        layout.scroll_width(),
128        0f32,
129        "scroll_width of node {:?}. Expected {}. Actual {}",
130        node01,
131        0f32,
132        layout.scroll_width()
133    );
134    #[cfg(feature = "content_size")]
135    assert_eq!(
136        layout.scroll_height(),
137        0f32,
138        "scroll_height of node {:?}. Expected {}. Actual {}",
139        node01,
140        0f32,
141        layout.scroll_height()
142    );
143}