gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/grid_span_2_max_content_auto_indefinite.rs Rust · 74 siq'ikuna · 4.1 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename `Points`/`points` to `Length`/`length` in many APIs (#459) 55abeaf2e · Simon Sapin ·

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