tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Definiciones

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_min_content_flex_row.rs Rust · 158 líneas · 8.6 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_min_content_flex_row__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\u{200b}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\u{200b}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\u{200b}HH", crate::WritingMode::Horizontal),
23        )
24        .unwrap();
25    let node0 = taffy
26        .new_with_children(
27            taffy::style::Style { display: taffy::style::Display::Flex, ..Default::default() },
28            &[node00, node01, node02],
29        )
30        .unwrap();
31    let node = taffy
32        .new_with_children(
33            taffy::style::Style {
34                display: taffy::style::Display::Grid,
35                grid_template_rows: vec![length(40f32)],
36                grid_template_columns: vec![min_content()],
37                ..Default::default()
38            },
39            &[node0],
40        )
41        .unwrap();
42    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
43    println!("\nComputed tree:");
44    taffy.print_tree(node);
45    println!();
46    let layout = taffy.layout(node).unwrap();
47    let Layout { size, location, .. } = layout;
48    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
49    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
52    let layout = taffy.layout(node0).unwrap();
53    let Layout { size, location, .. } = layout;
54    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
55    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
58    let layout = taffy.layout(node00).unwrap();
59    let Layout { size, location, .. } = layout;
60    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
61    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
62    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
63    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
64    let layout = taffy.layout(node01).unwrap();
65    let Layout { size, location, .. } = layout;
66    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
67    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node01, 40f32, size.height);
68    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
69    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
70    let layout = taffy.layout(node02).unwrap();
71    let Layout { size, location, .. } = layout;
72    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
73    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node02, 40f32, size.height);
74    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node02, 40f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node02, 0f32, location.y);
76}
77
78#[test]
79#[allow(non_snake_case)]
80fn grid_min_content_flex_row__content_box() {
81    #[allow(unused_imports)]
82    use taffy::{prelude::*, Layout};
83    let mut taffy = crate::new_test_tree();
84    let node00 = taffy
85        .new_leaf_with_context(
86            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
87            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
88        )
89        .unwrap();
90    let node01 = taffy
91        .new_leaf_with_context(
92            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
93            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
94        )
95        .unwrap();
96    let node02 = taffy
97        .new_leaf_with_context(
98            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
99            crate::TestNodeContext::ahem_text("HH\u{200b}HH", crate::WritingMode::Horizontal),
100        )
101        .unwrap();
102    let node0 = taffy
103        .new_with_children(
104            taffy::style::Style {
105                display: taffy::style::Display::Flex,
106                box_sizing: taffy::style::BoxSizing::ContentBox,
107                ..Default::default()
108            },
109            &[node00, node01, node02],
110        )
111        .unwrap();
112    let node = taffy
113        .new_with_children(
114            taffy::style::Style {
115                display: taffy::style::Display::Grid,
116                box_sizing: taffy::style::BoxSizing::ContentBox,
117                grid_template_rows: vec![length(40f32)],
118                grid_template_columns: vec![min_content()],
119                ..Default::default()
120            },
121            &[node0],
122        )
123        .unwrap();
124    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
125    println!("\nComputed tree:");
126    taffy.print_tree(node);
127    println!();
128    let layout = taffy.layout(node).unwrap();
129    let Layout { size, location, .. } = layout;
130    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
131    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
132    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
133    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
134    let layout = taffy.layout(node0).unwrap();
135    let Layout { size, location, .. } = layout;
136    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
137    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
138    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
139    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
140    let layout = taffy.layout(node00).unwrap();
141    let Layout { size, location, .. } = layout;
142    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
143    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
144    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
145    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
146    let layout = taffy.layout(node01).unwrap();
147    let Layout { size, location, .. } = layout;
148    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
149    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node01, 40f32, size.height);
150    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
151    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
152    let layout = taffy.layout(node02).unwrap();
153    let Layout { size, location, .. } = layout;
154    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02, 20f32, size.width);
155    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node02, 40f32, size.height);
156    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node02, 40f32, location.x);
157    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node02, 0f32, location.y);
158}