gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

⎇ 0.4.x tests/generated/grid/grid_relayout_vertical_text.rs Rust · 113 líneas · 4.4 KB Historia Quién tocó qué crudo

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

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