gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Definiciones

⎇ 0.4.x tests/generated/grid/grid_align_items_sized_stretch.rs Rust · 120 líneas · 5.1 KB Historia Quién tocó qué crudo

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn grid_align_items_sized_stretch() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::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            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::Length(20f32),
12                height: taffy::style::Dimension::Length(20f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy
18        .new_leaf(taffy::style::Style {
19            grid_row: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
20            grid_column: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
21            size: taffy::geometry::Size {
22                width: taffy::style::Dimension::Length(60f32),
23                height: taffy::style::Dimension::Length(60f32),
24            },
25            ..Default::default()
26        })
27        .unwrap();
28    let node = taffy
29        .new_with_children(
30            taffy::style::Style {
31                display: taffy::style::Display::Grid,
32                align_items: Some(taffy::style::AlignItems::Stretch),
33                grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
34                grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
35                size: taffy::geometry::Size {
36                    width: taffy::style::Dimension::Length(120f32),
37                    height: taffy::style::Dimension::Length(120f32),
38                },
39                ..Default::default()
40            },
41            &[node0, node1],
42        )
43        .unwrap();
44    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
45    println!("\nComputed tree:");
46    taffy.print_tree(node);
47    println!();
48    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
49    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
50    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
51    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
52    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
54    #[cfg(feature = "content_size")]
55    assert_eq!(
56        layout.scroll_width(),
57        20f32,
58        "scroll_width of node {:?}. Expected {}. Actual {}",
59        node,
60        20f32,
61        layout.scroll_width()
62    );
63    #[cfg(feature = "content_size")]
64    assert_eq!(
65        layout.scroll_height(),
66        20f32,
67        "scroll_height of node {:?}. Expected {}. Actual {}",
68        node,
69        20f32,
70        layout.scroll_height()
71    );
72    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
73    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
74    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
75    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
76    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
77    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
78    #[cfg(feature = "content_size")]
79    assert_eq!(
80        layout.scroll_width(),
81        0f32,
82        "scroll_width of node {:?}. Expected {}. Actual {}",
83        node0,
84        0f32,
85        layout.scroll_width()
86    );
87    #[cfg(feature = "content_size")]
88    assert_eq!(
89        layout.scroll_height(),
90        0f32,
91        "scroll_height of node {:?}. Expected {}. Actual {}",
92        node0,
93        0f32,
94        layout.scroll_height()
95    );
96    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
97    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
98    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1, 60f32, size.width);
99    assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1, 60f32, size.height);
100    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node1, 80f32, location.x);
101    assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node1, 80f32, location.y);
102    #[cfg(feature = "content_size")]
103    assert_eq!(
104        layout.scroll_width(),
105        0f32,
106        "scroll_width of node {:?}. Expected {}. Actual {}",
107        node1,
108        0f32,
109        layout.scroll_width()
110    );
111    #[cfg(feature = "content_size")]
112    assert_eq!(
113        layout.scroll_height(),
114        0f32,
115        "scroll_height of node {:?}. Expected {}. Actual {}",
116        node1,
117        0f32,
118        layout.scroll_height()
119    );
120}