gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/align_items_center_min_max_with_padding.rs Rust · 90 líneas · 3.6 KB Historia Quién tocó qué crudo

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

1#[test]
2fn align_items_center_min_max_with_padding() {
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            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(62f32),
10                height: taffy::style::Dimension::Length(62f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node = taffy
16        .new_with_children(
17            taffy::style::Style {
18                align_items: Some(taffy::style::AlignItems::Center),
19                min_size: taffy::geometry::Size {
20                    width: taffy::style::Dimension::Length(320f32),
21                    height: taffy::style::Dimension::Length(72f32),
22                },
23                max_size: taffy::geometry::Size {
24                    width: taffy::style::Dimension::Length(320f32),
25                    height: taffy::style::Dimension::Length(504f32),
26                },
27                padding: taffy::geometry::Rect {
28                    left: zero(),
29                    right: zero(),
30                    top: taffy::style::LengthPercentage::Length(8f32),
31                    bottom: taffy::style::LengthPercentage::Length(8f32),
32                },
33                ..Default::default()
34            },
35            &[node0],
36        )
37        .unwrap();
38    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
39    println!("\nComputed tree:");
40    taffy.print_tree(node);
41    println!();
42    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
43    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
44    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
45    assert_eq!(size.height, 78f32, "height of node {:?}. Expected {}. Actual {}", node, 78f32, size.height);
46    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
47    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
48    #[cfg(feature = "content_size")]
49    assert_eq!(
50        layout.scroll_width(),
51        0f32,
52        "scroll_width of node {:?}. Expected {}. Actual {}",
53        node,
54        0f32,
55        layout.scroll_width()
56    );
57    #[cfg(feature = "content_size")]
58    assert_eq!(
59        layout.scroll_height(),
60        0f32,
61        "scroll_height of node {:?}. Expected {}. Actual {}",
62        node,
63        0f32,
64        layout.scroll_height()
65    );
66    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
67    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
68    assert_eq!(size.width, 62f32, "width of node {:?}. Expected {}. Actual {}", node0, 62f32, size.width);
69    assert_eq!(size.height, 62f32, "height of node {:?}. Expected {}. Actual {}", node0, 62f32, size.height);
70    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
71    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
72    #[cfg(feature = "content_size")]
73    assert_eq!(
74        layout.scroll_width(),
75        0f32,
76        "scroll_width of node {:?}. Expected {}. Actual {}",
77        node0,
78        0f32,
79        layout.scroll_width()
80    );
81    #[cfg(feature = "content_size")]
82    assert_eq!(
83        layout.scroll_height(),
84        0f32,
85        "scroll_height of node {:?}. Expected {}. Actual {}",
86        node0,
87        0f32,
88        layout.scroll_height()
89    );
90}