gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/flex_grow_within_constrained_max_column.rs Rust · 106 líneas · 4.3 KB Historia Quién tocó qué crudo

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

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