tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Sutichaykuna

⎇ float-layout tests/generated/gridflex/gridflex_column_integration.rs Rust · 182 siq'ikuna · 10.1 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_column_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
43        .new_with_children(
44            taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, ..Default::default() },
45            &[node0],
46        )
47        .unwrap();
48    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
49    println!("\nComputed tree:");
50    taffy.print_tree(node);
51    println!();
52    let layout = taffy.layout(node).unwrap();
53    let Layout { size, location, .. } = layout;
54    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node, 40f32, size.width);
55    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
58    let layout = taffy.layout(node0).unwrap();
59    let Layout { size, location, .. } = layout;
60    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
61    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
62    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
63    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
64    let layout = taffy.layout(node00).unwrap();
65    let Layout { size, location, .. } = layout;
66    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
67    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
68    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
69    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
70    let layout = taffy.layout(node01).unwrap();
71    let Layout { size, location, .. } = layout;
72    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
73    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
74    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
76    let layout = taffy.layout(node02).unwrap();
77    let Layout { size, location, .. } = layout;
78    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
79    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02, 10f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
81    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02, 10f32, location.y);
82    let layout = taffy.layout(node03).unwrap();
83    let Layout { size, location, .. } = layout;
84    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node03, 20f32, size.width);
85    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03, 10f32, size.height);
86    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03, 20f32, location.x);
87    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03, 10f32, location.y);
88}
89
90#[test]
91#[allow(non_snake_case)]
92fn gridflex_column_integration__content_box() {
93    #[allow(unused_imports)]
94    use taffy::{prelude::*, Layout};
95    let mut taffy = crate::new_test_tree();
96    let node00 = taffy
97        .new_leaf_with_context(
98            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
99            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
100        )
101        .unwrap();
102    let node01 = taffy
103        .new_leaf_with_context(
104            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
105            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
106        )
107        .unwrap();
108    let node02 = taffy
109        .new_leaf_with_context(
110            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
111            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
112        )
113        .unwrap();
114    let node03 = taffy
115        .new_leaf_with_context(
116            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
117            crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
118        )
119        .unwrap();
120    let node0 = taffy
121        .new_with_children(
122            taffy::style::Style {
123                display: taffy::style::Display::Grid,
124                box_sizing: taffy::style::BoxSizing::ContentBox,
125                grid_template_rows: vec![fr(1f32), fr(1f32)],
126                grid_template_columns: vec![fr(1f32), fr(1f32)],
127                ..Default::default()
128            },
129            &[node00, node01, node02, node03],
130        )
131        .unwrap();
132    let node = taffy
133        .new_with_children(
134            taffy::style::Style {
135                box_sizing: taffy::style::BoxSizing::ContentBox,
136                flex_direction: taffy::style::FlexDirection::Column,
137                ..Default::default()
138            },
139            &[node0],
140        )
141        .unwrap();
142    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
143    println!("\nComputed tree:");
144    taffy.print_tree(node);
145    println!();
146    let layout = taffy.layout(node).unwrap();
147    let Layout { size, location, .. } = layout;
148    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node, 40f32, size.width);
149    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
150    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
151    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
152    let layout = taffy.layout(node0).unwrap();
153    let Layout { size, location, .. } = layout;
154    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
155    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
156    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
157    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
158    let layout = taffy.layout(node00).unwrap();
159    let Layout { size, location, .. } = layout;
160    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
161    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
162    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
163    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
164    let layout = taffy.layout(node01).unwrap();
165    let Layout { size, location, .. } = layout;
166    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
167    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
168    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
169    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
170    let layout = taffy.layout(node02).unwrap();
171    let Layout { size, location, .. } = layout;
172    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
173    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02, 10f32, size.height);
174    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
175    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02, 10f32, location.y);
176    let layout = taffy.layout(node03).unwrap();
177    let Layout { size, location, .. } = layout;
178    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node03, 20f32, size.width);
179    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03, 10f32, size.height);
180    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03, 20f32, location.x);
181    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03, 10f32, location.y);
182}