gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 245JavaScript 8CSS 61138 Sutichaykuna

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/intrinsic_sizing_main_size_row_wrap.rs Rust · 62 siq'ikuna · 3.1 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement §9.9.1. Flex Container Intrinsic Main Sizes (#354) bf3dfaec9 · Nico Burns ·

1#[test]
2fn intrinsic_sizing_main_size_row_wrap() {
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";
12                super::measure_standard_text(
13                    known_dimensions,
14                    available_space,
15                    TEXT,
16                    super::WritingMode::Horizontal,
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";
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 { flex_wrap: taffy::style::FlexWrap::Wrap, ..Default::default() },
40            &[node0, node1],
41        )
42        .unwrap();
43    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
44    println!("\nComputed tree:");
45    taffy::debug::print_tree(&taffy, node);
46    println!();
47    let Layout { size, location, .. } = taffy.layout(node).unwrap();
48    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 80f32, size.width);
49    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 10f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
52    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
53    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
54    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
57    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
58    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.width);
59    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 10f32, size.height);
60    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.x);
61    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
62}