gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1344 Definitions

⎇ 0.5.x tests/generated/flex/bevy_issue_8017_reduced.rs Rust · 167 lines · 6.8 KB History Who touched what raw

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

1#[test]
2fn bevy_issue_8017_reduced() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
7    let node0 = taffy
8        .new_with_children(
9            taffy::style::Style {
10                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.5f32) },
11                ..Default::default()
12            },
13            &[node00],
14        )
15        .unwrap();
16    let node10 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
17    let node1 = taffy
18        .new_with_children(
19            taffy::style::Style {
20                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.5f32) },
21                ..Default::default()
22            },
23            &[node10],
24        )
25        .unwrap();
26    let node = taffy
27        .new_with_children(
28            taffy::style::Style {
29                flex_direction: taffy::style::FlexDirection::Column,
30                gap: taffy::geometry::Size {
31                    width: taffy::style::LengthPercentage::Length(8f32),
32                    height: taffy::style::LengthPercentage::Length(8f32),
33                },
34                size: taffy::geometry::Size {
35                    width: taffy::style::Dimension::Length(200f32),
36                    height: taffy::style::Dimension::Length(400f32),
37                },
38                ..Default::default()
39            },
40            &[node0, node1],
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, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
50    assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node, 400f32, 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, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
74    assert_eq!(size.height, 196f32, "height of node {:?}. Expected {}. Actual {}", node0, 196f32, 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, 0f32, "width of node {:?}. Expected {}. Actual {}", node00, 0f32, size.width);
98    assert_eq!(size.height, 196f32, "height of node {:?}. Expected {}. Actual {}", node00, 196f32, 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(node1).unwrap();
121    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width);
122    assert_eq!(size.height, 196f32, "height of node {:?}. Expected {}. Actual {}", node1, 196f32, size.height);
123    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
124    assert_eq!(location.y, 204f32, "y of node {:?}. Expected {}. Actual {}", node1, 204f32, location.y);
125    #[cfg(feature = "content_size")]
126    assert_eq!(
127        layout.scroll_width(),
128        0f32,
129        "scroll_width of node {:?}. Expected {}. Actual {}",
130        node1,
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        node1,
140        0f32,
141        layout.scroll_height()
142    );
143    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
144    let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
145    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node10, 0f32, size.width);
146    assert_eq!(size.height, 196f32, "height of node {:?}. Expected {}. Actual {}", node10, 196f32, size.height);
147    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
148    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
149    #[cfg(feature = "content_size")]
150    assert_eq!(
151        layout.scroll_width(),
152        0f32,
153        "scroll_width of node {:?}. Expected {}. Actual {}",
154        node10,
155        0f32,
156        layout.scroll_width()
157    );
158    #[cfg(feature = "content_size")]
159    assert_eq!(
160        layout.scroll_height(),
161        0f32,
162        "scroll_height of node {:?}. Expected {}. Actual {}",
163        node10,
164        0f32,
165        layout.scroll_height()
166    );
167}