gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 238TOML 3CSS 11112 Definitions

⎇ 0.5.x tests/generated/gridflex/gridflex_column_integration.rs Rust · 211 lines · 8.3 KB History Who touched what raw

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

1#[test]
2fn gridflex_column_integration() {
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_with_context(
8            taffy::style::Style { ..Default::default() },
9            crate::TextMeasure {
10                text_content: "HH",
11                writing_mode: crate::WritingMode::Horizontal,
12                _aspect_ratio: None,
13            },
14        )
15        .unwrap();
16    let node01 = taffy
17        .new_leaf_with_context(
18            taffy::style::Style { ..Default::default() },
19            crate::TextMeasure {
20                text_content: "HH",
21                writing_mode: crate::WritingMode::Horizontal,
22                _aspect_ratio: None,
23            },
24        )
25        .unwrap();
26    let node02 = taffy
27        .new_leaf_with_context(
28            taffy::style::Style { ..Default::default() },
29            crate::TextMeasure {
30                text_content: "HH",
31                writing_mode: crate::WritingMode::Horizontal,
32                _aspect_ratio: None,
33            },
34        )
35        .unwrap();
36    let node03 = taffy
37        .new_leaf_with_context(
38            taffy::style::Style { ..Default::default() },
39            crate::TextMeasure {
40                text_content: "HH",
41                writing_mode: crate::WritingMode::Horizontal,
42                _aspect_ratio: None,
43            },
44        )
45        .unwrap();
46    let node0 = taffy
47        .new_with_children(
48            taffy::style::Style {
49                display: taffy::style::Display::Grid,
50                grid_template_rows: vec![fr(1f32), fr(1f32)],
51                grid_template_columns: vec![fr(1f32), fr(1f32)],
52                ..Default::default()
53            },
54            &[node00, node01, node02, node03],
55        )
56        .unwrap();
57    let node = taffy
58        .new_with_children(
59            taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, ..Default::default() },
60            &[node0],
61        )
62        .unwrap();
63    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
64    println!("\nComputed tree:");
65    taffy.print_tree(node);
66    println!();
67    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
68    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
69    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node, 40f32, size.width);
70    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
73    #[cfg(feature = "content_size")]
74    assert_eq!(
75        layout.scroll_width(),
76        0f32,
77        "scroll_width of node {:?}. Expected {}. Actual {}",
78        node,
79        0f32,
80        layout.scroll_width()
81    );
82    #[cfg(feature = "content_size")]
83    assert_eq!(
84        layout.scroll_height(),
85        0f32,
86        "scroll_height of node {:?}. Expected {}. Actual {}",
87        node,
88        0f32,
89        layout.scroll_height()
90    );
91    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
92    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
93    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
94    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
97    #[cfg(feature = "content_size")]
98    assert_eq!(
99        layout.scroll_width(),
100        0f32,
101        "scroll_width of node {:?}. Expected {}. Actual {}",
102        node0,
103        0f32,
104        layout.scroll_width()
105    );
106    #[cfg(feature = "content_size")]
107    assert_eq!(
108        layout.scroll_height(),
109        0f32,
110        "scroll_height of node {:?}. Expected {}. Actual {}",
111        node0,
112        0f32,
113        layout.scroll_height()
114    );
115    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
116    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
117    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
118    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
119    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
120    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
121    #[cfg(feature = "content_size")]
122    assert_eq!(
123        layout.scroll_width(),
124        0f32,
125        "scroll_width of node {:?}. Expected {}. Actual {}",
126        node00,
127        0f32,
128        layout.scroll_width()
129    );
130    #[cfg(feature = "content_size")]
131    assert_eq!(
132        layout.scroll_height(),
133        0f32,
134        "scroll_height of node {:?}. Expected {}. Actual {}",
135        node00,
136        0f32,
137        layout.scroll_height()
138    );
139    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
140    let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
141    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
142    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01, 10f32, size.height);
143    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
144    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
145    #[cfg(feature = "content_size")]
146    assert_eq!(
147        layout.scroll_width(),
148        0f32,
149        "scroll_width of node {:?}. Expected {}. Actual {}",
150        node01,
151        0f32,
152        layout.scroll_width()
153    );
154    #[cfg(feature = "content_size")]
155    assert_eq!(
156        layout.scroll_height(),
157        0f32,
158        "scroll_height of node {:?}. Expected {}. Actual {}",
159        node01,
160        0f32,
161        layout.scroll_height()
162    );
163    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
164    let layout @ Layout { size, location, .. } = taffy.layout(node02).unwrap();
165    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
166    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02, 10f32, size.height);
167    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02, 0f32, location.x);
168    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02, 10f32, location.y);
169    #[cfg(feature = "content_size")]
170    assert_eq!(
171        layout.scroll_width(),
172        0f32,
173        "scroll_width of node {:?}. Expected {}. Actual {}",
174        node02,
175        0f32,
176        layout.scroll_width()
177    );
178    #[cfg(feature = "content_size")]
179    assert_eq!(
180        layout.scroll_height(),
181        0f32,
182        "scroll_height of node {:?}. Expected {}. Actual {}",
183        node02,
184        0f32,
185        layout.scroll_height()
186    );
187    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
188    let layout @ Layout { size, location, .. } = taffy.layout(node03).unwrap();
189    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node03, 20f32, size.width);
190    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03, 10f32, size.height);
191    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03, 20f32, location.x);
192    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03, 10f32, location.y);
193    #[cfg(feature = "content_size")]
194    assert_eq!(
195        layout.scroll_width(),
196        0f32,
197        "scroll_width of node {:?}. Expected {}. Actual {}",
198        node03,
199        0f32,
200        layout.scroll_width()
201    );
202    #[cfg(feature = "content_size")]
203    assert_eq!(
204        layout.scroll_height(),
205        0f32,
206        "scroll_height of node {:?}. Expected {}. Actual {}",
207        node03,
208        0f32,
209        layout.scroll_height()
210    );
211}