gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 245JavaScript 8CSS 61137 Definiciones

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