gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 708HTML 661Markdown 12TOML 62346 Definitions

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/gridflex_row_integration.rs Rust · 113 lines · 5.9 KB History Who touched what raw

Grid: Rename Flex to Fraction (#350) 71027a8de · Nico Burns ·

1#[test]
2fn gridflex_row_integration() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node00 = 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";
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 node01 = 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";
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 node02 = taffy
38        .new_leaf_with_measure(
39            taffy::style::Style { ..Default::default() },
40            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
41                const TEXT: &str = "HH";
42                super::measure_standard_text(
43                    known_dimensions,
44                    available_space,
45                    TEXT,
46                    super::WritingMode::Horizontal,
47                    None,
48                )
49            }),
50        )
51        .unwrap();
52    let node03 = taffy
53        .new_leaf_with_measure(
54            taffy::style::Style { ..Default::default() },
55            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
56                const TEXT: &str = "HH";
57                super::measure_standard_text(
58                    known_dimensions,
59                    available_space,
60                    TEXT,
61                    super::WritingMode::Horizontal,
62                    None,
63                )
64            }),
65        )
66        .unwrap();
67    let node0 = taffy
68        .new_with_children(
69            taffy::style::Style {
70                display: taffy::style::Display::Grid,
71                grid_template_rows: vec![fr(1f32), fr(1f32)],
72                grid_template_columns: vec![fr(1f32), fr(1f32)],
73                ..Default::default()
74            },
75            &[node00, node01, node02, node03],
76        )
77        .unwrap();
78    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
79    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
80    println!("\nComputed tree:");
81    taffy::debug::print_tree(&taffy, node);
82    println!();
83    let Layout { size, location, .. } = taffy.layout(node).unwrap();
84    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.width);
85    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.height);
86    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
87    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
88    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
89    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
90    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
91    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
92    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
93    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
94    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.width);
95    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, size.height);
96    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
97    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
98    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
99    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, size.width);
100    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 10f32, size.height);
101    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, location.x);
102    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.y);
103    let Layout { size, location, .. } = taffy.layout(node02).unwrap();
104    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02.data(), 20f32, size.width);
105    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02.data(), 10f32, size.height);
106    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02.data(), 0f32, location.x);
107    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02.data(), 10f32, location.y);
108    let Layout { size, location, .. } = taffy.layout(node03).unwrap();
109    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node03.data(), 20f32, size.width);
110    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03.data(), 10f32, size.height);
111    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03.data(), 20f32, location.x);
112    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03.data(), 10f32, location.y);
113}