tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 238TOML 3CSS 11112 Definiciones

⎇ 477ff4aff498cbae4cdfbf0cda1ee5b04c784f08 tests/generated/grid/grid_basic_implicit_tracks.rs Rust · 103 líneas · 4.1 KB Historia Quién tocó qué crudo

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

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