tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Definitions

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_relayout_vertical_text.rs Rust · 112 lines · 5.8 KB History Who touched what raw

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

1#[test]
2#[allow(non_snake_case)]
3fn grid_relayout_vertical_text__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 { ..Default::default() },
10            crate::TestNodeContext::ahem_text(
11                "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH",
12                crate::WritingMode::Vertical,
13            ),
14        )
15        .unwrap();
16    let node1 = taffy
17        .new_leaf_with_context(
18            taffy::style::Style { ..Default::default() },
19            crate::TestNodeContext::ahem_text("HH\u{200b}HH\u{200b}HH", crate::WritingMode::Horizontal),
20        )
21        .unwrap();
22    let node = taffy
23        .new_with_children(
24            taffy::style::Style {
25                display: taffy::style::Display::Grid,
26                grid_template_rows: vec![length(40f32)],
27                grid_template_columns: vec![min_content()],
28                ..Default::default()
29            },
30            &[node0, node1],
31        )
32        .unwrap();
33    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
34    println!("\nComputed tree:");
35    taffy.print_tree(node);
36    println!();
37    let layout = taffy.layout(node).unwrap();
38    let Layout { size, location, .. } = layout;
39    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node, 40f32, size.width);
40    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node, 60f32, size.height);
41    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
42    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
43    let layout = taffy.layout(node0).unwrap();
44    let Layout { size, location, .. } = layout;
45    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
46    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
48    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
49    let layout = taffy.layout(node1).unwrap();
50    let Layout { size, location, .. } = layout;
51    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
52    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
53    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
54    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
55}
56
57#[test]
58#[allow(non_snake_case)]
59fn grid_relayout_vertical_text__content_box() {
60    #[allow(unused_imports)]
61    use taffy::{prelude::*, Layout};
62    let mut taffy = crate::new_test_tree();
63    let node0 = taffy
64        .new_leaf_with_context(
65            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
66            crate::TestNodeContext::ahem_text(
67                "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH",
68                crate::WritingMode::Vertical,
69            ),
70        )
71        .unwrap();
72    let node1 = taffy
73        .new_leaf_with_context(
74            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
75            crate::TestNodeContext::ahem_text("HH\u{200b}HH\u{200b}HH", crate::WritingMode::Horizontal),
76        )
77        .unwrap();
78    let node = taffy
79        .new_with_children(
80            taffy::style::Style {
81                display: taffy::style::Display::Grid,
82                box_sizing: taffy::style::BoxSizing::ContentBox,
83                grid_template_rows: vec![length(40f32)],
84                grid_template_columns: vec![min_content()],
85                ..Default::default()
86            },
87            &[node0, node1],
88        )
89        .unwrap();
90    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
91    println!("\nComputed tree:");
92    taffy.print_tree(node);
93    println!();
94    let layout = taffy.layout(node).unwrap();
95    let Layout { size, location, .. } = layout;
96    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node, 40f32, size.width);
97    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node, 60f32, size.height);
98    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
99    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
100    let layout = taffy.layout(node0).unwrap();
101    let Layout { size, location, .. } = layout;
102    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
103    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
104    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
105    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
106    let layout = taffy.layout(node1).unwrap();
107    let Layout { size, location, .. } = layout;
108    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
109    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
110    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
111    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
112}