tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 238Markdown 7TOML 41214 Definiciones

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_overflow_rows.rs Rust · 175 líneas · 10.9 KB Historia Quién tocó qué crudo

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

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