tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 979HTML 924Markdown 12TOML 82994 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/gridflex/gridflex_row_integration.rs Rust · 173 siq'ikuna · 9.9 KB Ñawpa willay Pi imata llamkarqan ch'uya

Add `taffy_test_helpers` crate (#755) 2a3e8476b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn gridflex_row_integration__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node00 = taffy
8        .new_leaf_with_context(
9            taffy::style::Style { ..Default::default() },
10            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
11        )
12        .unwrap();
13    let node01 = taffy
14        .new_leaf_with_context(
15            taffy::style::Style { ..Default::default() },
16            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
17        )
18        .unwrap();
19    let node02 = taffy
20        .new_leaf_with_context(
21            taffy::style::Style { ..Default::default() },
22            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
23        )
24        .unwrap();
25    let node03 = taffy
26        .new_leaf_with_context(
27            taffy::style::Style { ..Default::default() },
28            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
29        )
30        .unwrap();
31    let node0 = taffy
32        .new_with_children(
33            taffy::style::Style {
34                display: taffy::style::Display::Grid,
35                grid_template_rows: vec![fr(1f32), fr(1f32)],
36                grid_template_columns: vec![fr(1f32), fr(1f32)],
37                ..Default::default()
38            },
39            &[node00, node01, node02, node03],
40        )
41        .unwrap();
42    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).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    let layout = taffy.layout(node).unwrap();
48    let Layout { size, location, .. } = layout;
49    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node, 40f32, size.width);
50    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, 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    let layout = taffy.layout(node0).unwrap();
54    let Layout { size, location, .. } = layout;
55    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
56    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
57    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
58    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
59    let layout = taffy.layout(node00).unwrap();
60    let Layout { size, location, .. } = layout;
61    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
62    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
63    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
64    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
65    let layout = taffy.layout(node01).unwrap();
66    let Layout { size, location, .. } = layout;
67    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
68    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
69    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
71    let layout = taffy.layout(node02).unwrap();
72    let Layout { size, location, .. } = layout;
73    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
74    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02, 10f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
76    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02, 10f32, location.y);
77    let layout = taffy.layout(node03).unwrap();
78    let Layout { size, location, .. } = layout;
79    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node03, 20f32, size.width);
80    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03, 10f32, size.height);
81    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03, 20f32, location.x);
82    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03, 10f32, location.y);
83}
84
85#[test]
86#[allow(non_snake_case)]
87fn gridflex_row_integration__content_box() {
88    #[allow(unused_imports)]
89    use taffy::{prelude::*, Layout};
90    let mut taffy = crate::new_test_tree();
91    let node00 = taffy
92        .new_leaf_with_context(
93            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
94            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
95        )
96        .unwrap();
97    let node01 = taffy
98        .new_leaf_with_context(
99            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
100            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
101        )
102        .unwrap();
103    let node02 = taffy
104        .new_leaf_with_context(
105            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
106            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
107        )
108        .unwrap();
109    let node03 = taffy
110        .new_leaf_with_context(
111            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
112            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
113        )
114        .unwrap();
115    let node0 = taffy
116        .new_with_children(
117            taffy::style::Style {
118                display: taffy::style::Display::Grid,
119                box_sizing: taffy::style::BoxSizing::ContentBox,
120                grid_template_rows: vec![fr(1f32), fr(1f32)],
121                grid_template_columns: vec![fr(1f32), fr(1f32)],
122                ..Default::default()
123            },
124            &[node00, node01, node02, node03],
125        )
126        .unwrap();
127    let node = taffy
128        .new_with_children(
129            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
130            &[node0],
131        )
132        .unwrap();
133    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
134    println!("\nComputed tree:");
135    taffy.print_tree(node);
136    println!();
137    let layout = taffy.layout(node).unwrap();
138    let Layout { size, location, .. } = layout;
139    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node, 40f32, size.width);
140    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
141    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
142    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
143    let layout = taffy.layout(node0).unwrap();
144    let Layout { size, location, .. } = layout;
145    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
146    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
147    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
148    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
149    let layout = taffy.layout(node00).unwrap();
150    let Layout { size, location, .. } = layout;
151    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
152    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
153    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
154    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
155    let layout = taffy.layout(node01).unwrap();
156    let Layout { size, location, .. } = layout;
157    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
158    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
159    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
160    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
161    let layout = taffy.layout(node02).unwrap();
162    let Layout { size, location, .. } = layout;
163    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
164    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02, 10f32, size.height);
165    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
166    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02, 10f32, location.y);
167    let layout = taffy.layout(node03).unwrap();
168    let Layout { size, location, .. } = layout;
169    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node03, 20f32, size.width);
170    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03, 10f32, size.height);
171    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03, 20f32, location.x);
172    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03, 10f32, location.y);
173}