gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definiciones

⎇ 0.3.x tests/generated/grid_min_content_flex_column.rs Rust · 102 líneas · 5.1 KB Historia Quién tocó qué crudo

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

1#[test]
2fn grid_min_content_flex_column() {
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\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 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\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 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\u{200b}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 node0 = taffy
53        .new_with_children(
54            taffy::style::Style {
55                display: taffy::style::Display::Flex,
56                flex_direction: taffy::style::FlexDirection::Column,
57                ..Default::default()
58            },
59            &[node00, node01, node02],
60        )
61        .unwrap();
62    let node = taffy
63        .new_with_children(
64            taffy::style::Style {
65                display: taffy::style::Display::Grid,
66                grid_template_rows: vec![points(40f32)],
67                grid_template_columns: vec![min_content()],
68                ..Default::default()
69            },
70            &[node0],
71        )
72        .unwrap();
73    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
74    println!("\nComputed tree:");
75    taffy::debug::print_tree(&taffy, node);
76    println!();
77    let Layout { size, location, .. } = taffy.layout(node).unwrap();
78    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.width);
79    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
82    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
83    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
84    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
85    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
86    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
87    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
88    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.width);
89    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.height);
90    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
91    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
92    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
93    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, size.width);
94    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.x);
96    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, location.y);
97    let Layout { size, location, .. } = taffy.layout(node02).unwrap();
98    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02.data(), 20f32, size.width);
99    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02.data(), 20f32, size.height);
100    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02.data(), 0f32, location.x);
101    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node02.data(), 40f32, location.y);
102}