gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 0.5.x tests/generated/flex/flex_grow_within_constrained_min_column.rs Rust · 99 líneas · 4.1 KB Historia Quién tocó qué crudo

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

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