gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 976HTML 921Markdown 12TOML 82979 Definiciones

⎇ 0.5.x tests/generated/flex/child_min_max_width_flexing.rs Rust · 113 líneas · 4.5 KB Historia Quién tocó qué crudo

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

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