gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91841 Definiciones

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/bevy_issue_21240.rs Rust · 186 líneas · 11.4 KB Historia Quién tocó qué crudo

Create test for bevy issue 21240 (#869) 368b7da13 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn bevy_issue_21240__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
9    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
10    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
11    let node4 = taffy
12        .new_leaf(taffy::style::Style {
13            grid_column: taffy::geometry::Line { start: line(1i16), end: line(-1i16) },
14            ..Default::default()
15        })
16        .unwrap();
17    let node5 = taffy
18        .new_leaf(taffy::style::Style {
19            grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(4u16) },
20            ..Default::default()
21        })
22        .unwrap();
23    let node = taffy
24        .new_with_children(
25            taffy::style::Style {
26                display: taffy::style::Display::Grid,
27                gap: taffy::geometry::Size { width: length(8f32), height: length(8f32) },
28                grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
29                grid_template_columns: vec![length(40f32), length(40f32), length(40f32), length(40f32)],
30                padding: taffy::geometry::Rect {
31                    left: length(8f32),
32                    right: length(8f32),
33                    top: length(8f32),
34                    bottom: length(8f32),
35                },
36                ..Default::default()
37            },
38            &[node0, node1, node2, node3, node4, node5],
39        )
40        .unwrap();
41    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
42    println!("\nComputed tree:");
43    taffy.print_tree(node);
44    println!();
45    let layout = taffy.layout(node).unwrap();
46    let Layout { size, location, .. } = layout;
47    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
48    assert_eq!(size.height, 152f32, "height of node {:?}. Expected {}. Actual {}", node, 152f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
51    let layout = taffy.layout(node0).unwrap();
52    let Layout { size, location, .. } = layout;
53    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
54    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
55    assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node0, 8f32, location.x);
56    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
57    let layout = taffy.layout(node1).unwrap();
58    let Layout { size, location, .. } = layout;
59    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
60    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
61    assert_eq!(location.x, 56f32, "x of node {:?}. Expected {}. Actual {}", node1, 56f32, location.x);
62    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node1, 8f32, location.y);
63    let layout = taffy.layout(node2).unwrap();
64    let Layout { size, location, .. } = layout;
65    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
66    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
67    assert_eq!(location.x, 104f32, "x of node {:?}. Expected {}. Actual {}", node2, 104f32, location.x);
68    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node2, 8f32, location.y);
69    let layout = taffy.layout(node3).unwrap();
70    let Layout { size, location, .. } = layout;
71    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
72    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
73    assert_eq!(location.x, 152f32, "x of node {:?}. Expected {}. Actual {}", node3, 152f32, location.x);
74    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node3, 8f32, location.y);
75    let layout = taffy.layout(node4).unwrap();
76    let Layout { size, location, .. } = layout;
77    assert_eq!(size.width, 184f32, "width of node {:?}. Expected {}. Actual {}", node4, 184f32, size.width);
78    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
79    assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node4, 8f32, location.x);
80    assert_eq!(location.y, 56f32, "y of node {:?}. Expected {}. Actual {}", node4, 56f32, location.y);
81    let layout = taffy.layout(node5).unwrap();
82    let Layout { size, location, .. } = layout;
83    assert_eq!(size.width, 184f32, "width of node {:?}. Expected {}. Actual {}", node5, 184f32, size.width);
84    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
85    assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node5, 8f32, location.x);
86    assert_eq!(location.y, 104f32, "y of node {:?}. Expected {}. Actual {}", node5, 104f32, location.y);
87}
88
89#[test]
90#[allow(non_snake_case)]
91fn bevy_issue_21240__content_box() {
92    #[allow(unused_imports)]
93    use taffy::{prelude::*, Layout};
94    let mut taffy = crate::new_test_tree();
95    let node0 = taffy
96        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
97        .unwrap();
98    let node1 = taffy
99        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
100        .unwrap();
101    let node2 = taffy
102        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
103        .unwrap();
104    let node3 = taffy
105        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
106        .unwrap();
107    let node4 = taffy
108        .new_leaf(taffy::style::Style {
109            box_sizing: taffy::style::BoxSizing::ContentBox,
110            grid_column: taffy::geometry::Line { start: line(1i16), end: line(-1i16) },
111            ..Default::default()
112        })
113        .unwrap();
114    let node5 = taffy
115        .new_leaf(taffy::style::Style {
116            box_sizing: taffy::style::BoxSizing::ContentBox,
117            grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(4u16) },
118            ..Default::default()
119        })
120        .unwrap();
121    let node = taffy
122        .new_with_children(
123            taffy::style::Style {
124                display: taffy::style::Display::Grid,
125                box_sizing: taffy::style::BoxSizing::ContentBox,
126                gap: taffy::geometry::Size { width: length(8f32), height: length(8f32) },
127                grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
128                grid_template_columns: vec![length(40f32), length(40f32), length(40f32), length(40f32)],
129                padding: taffy::geometry::Rect {
130                    left: length(8f32),
131                    right: length(8f32),
132                    top: length(8f32),
133                    bottom: length(8f32),
134                },
135                ..Default::default()
136            },
137            &[node0, node1, node2, node3, node4, node5],
138        )
139        .unwrap();
140    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
141    println!("\nComputed tree:");
142    taffy.print_tree(node);
143    println!();
144    let layout = taffy.layout(node).unwrap();
145    let Layout { size, location, .. } = layout;
146    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
147    assert_eq!(size.height, 152f32, "height of node {:?}. Expected {}. Actual {}", node, 152f32, size.height);
148    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
149    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
150    let layout = taffy.layout(node0).unwrap();
151    let Layout { size, location, .. } = layout;
152    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
153    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
154    assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node0, 8f32, location.x);
155    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
156    let layout = taffy.layout(node1).unwrap();
157    let Layout { size, location, .. } = layout;
158    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
159    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
160    assert_eq!(location.x, 56f32, "x of node {:?}. Expected {}. Actual {}", node1, 56f32, location.x);
161    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node1, 8f32, location.y);
162    let layout = taffy.layout(node2).unwrap();
163    let Layout { size, location, .. } = layout;
164    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2, 40f32, size.width);
165    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
166    assert_eq!(location.x, 104f32, "x of node {:?}. Expected {}. Actual {}", node2, 104f32, location.x);
167    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node2, 8f32, location.y);
168    let layout = taffy.layout(node3).unwrap();
169    let Layout { size, location, .. } = layout;
170    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node3, 40f32, size.width);
171    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node3, 40f32, size.height);
172    assert_eq!(location.x, 152f32, "x of node {:?}. Expected {}. Actual {}", node3, 152f32, location.x);
173    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node3, 8f32, location.y);
174    let layout = taffy.layout(node4).unwrap();
175    let Layout { size, location, .. } = layout;
176    assert_eq!(size.width, 184f32, "width of node {:?}. Expected {}. Actual {}", node4, 184f32, size.width);
177    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node4, 40f32, size.height);
178    assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node4, 8f32, location.x);
179    assert_eq!(location.y, 56f32, "y of node {:?}. Expected {}. Actual {}", node4, 56f32, location.y);
180    let layout = taffy.layout(node5).unwrap();
181    let Layout { size, location, .. } = layout;
182    assert_eq!(size.width, 184f32, "width of node {:?}. Expected {}. Actual {}", node5, 184f32, size.width);
183    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node5, 40f32, size.height);
184    assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node5, 8f32, location.x);
185    assert_eq!(location.y, 104f32, "y of node {:?}. Expected {}. Actual {}", node5, 104f32, location.y);
186}