tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Sutichaykuna

⎇ 0.3.x tests/generated/grid_relayout_vertical_text.rs Rust · 67 siq'ikuna · 3.3 KB Ñawpa willay Pi imata llamkarqan ch'uya

Fixes for aspect ratio and min/max sizes (#317) 610c92f31 · Nico Burns ·

1#[test]
2fn grid_relayout_vertical_text() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node0 = taffy
8        .new_leaf_with_measure(
9            taffy::style::Style { ..Default::default() },
10            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
11                const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH";
12                super::measure_standard_text(
13                    known_dimensions,
14                    available_space,
15                    TEXT,
16                    super::WritingMode::Vertical,
17                    None,
18                )
19            }),
20        )
21        .unwrap();
22    let node1 = taffy
23        .new_leaf_with_measure(
24            taffy::style::Style { ..Default::default() },
25            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
26                const TEXT: &str = "HH\u{200b}HH\u{200b}HH";
27                super::measure_standard_text(
28                    known_dimensions,
29                    available_space,
30                    TEXT,
31                    super::WritingMode::Horizontal,
32                    None,
33                )
34            }),
35        )
36        .unwrap();
37    let node = taffy
38        .new_with_children(
39            taffy::style::Style {
40                display: taffy::style::Display::Grid,
41                grid_template_rows: vec![points(40f32)],
42                grid_template_columns: vec![min_content()],
43                ..Default::default()
44            },
45            &[node0, node1],
46        )
47        .unwrap();
48    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
49    println!("\nComputed tree:");
50    taffy::debug::print_tree(&taffy, node);
51    println!();
52    let Layout { size, location, .. } = taffy.layout(node).unwrap();
53    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.width);
54    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 60f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
57    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
58    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
59    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
60    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
61    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
62    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
63    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.width);
64    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
65    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
66    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y);
67}