gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 976HTML 921Markdown 12TOML 82979 Definiciones

⎇ 0.5.x tests/generated/flex/align_flex_start_with_shrinking_children.rs Rust · 129 líneas · 5.3 KB Historia Quién tocó qué crudo

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

1#[test]
2fn align_flex_start_with_shrinking_children() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node000 =
7        taffy.new_leaf(taffy::style::Style { flex_grow: 1f32, flex_shrink: 1f32, ..Default::default() }).unwrap();
8    let node00 = taffy
9        .new_with_children(taffy::style::Style { flex_grow: 1f32, flex_shrink: 1f32, ..Default::default() }, &[node000])
10        .unwrap();
11    let node0 = taffy
12        .new_with_children(
13            taffy::style::Style { align_items: Some(taffy::style::AlignItems::FlexStart), ..Default::default() },
14            &[node00],
15        )
16        .unwrap();
17    let node = taffy
18        .new_with_children(
19            taffy::style::Style {
20                size: taffy::geometry::Size {
21                    width: taffy::style::Dimension::Length(500f32),
22                    height: taffy::style::Dimension::Length(500f32),
23                },
24                ..Default::default()
25            },
26            &[node0],
27        )
28        .unwrap();
29    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
30    println!("\nComputed tree:");
31    taffy.print_tree(node);
32    println!();
33    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
34    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
35    assert_eq!(size.width, 500f32, "width of node {:?}. Expected {}. Actual {}", node, 500f32, size.width);
36    assert_eq!(size.height, 500f32, "height of node {:?}. Expected {}. Actual {}", node, 500f32, size.height);
37    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
38    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
39    #[cfg(feature = "content_size")]
40    assert_eq!(
41        layout.scroll_width(),
42        0f32,
43        "scroll_width of node {:?}. Expected {}. Actual {}",
44        node,
45        0f32,
46        layout.scroll_width()
47    );
48    #[cfg(feature = "content_size")]
49    assert_eq!(
50        layout.scroll_height(),
51        0f32,
52        "scroll_height of node {:?}. Expected {}. Actual {}",
53        node,
54        0f32,
55        layout.scroll_height()
56    );
57    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
58    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
59    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
60    assert_eq!(size.height, 500f32, "height of node {:?}. Expected {}. Actual {}", node0, 500f32, size.height);
61    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
62    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
63    #[cfg(feature = "content_size")]
64    assert_eq!(
65        layout.scroll_width(),
66        0f32,
67        "scroll_width of node {:?}. Expected {}. Actual {}",
68        node0,
69        0f32,
70        layout.scroll_width()
71    );
72    #[cfg(feature = "content_size")]
73    assert_eq!(
74        layout.scroll_height(),
75        0f32,
76        "scroll_height of node {:?}. Expected {}. Actual {}",
77        node0,
78        0f32,
79        layout.scroll_height()
80    );
81    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
82    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
83    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node00, 0f32, size.width);
84    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00, 0f32, size.height);
85    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
86    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
87    #[cfg(feature = "content_size")]
88    assert_eq!(
89        layout.scroll_width(),
90        0f32,
91        "scroll_width of node {:?}. Expected {}. Actual {}",
92        node00,
93        0f32,
94        layout.scroll_width()
95    );
96    #[cfg(feature = "content_size")]
97    assert_eq!(
98        layout.scroll_height(),
99        0f32,
100        "scroll_height of node {:?}. Expected {}. Actual {}",
101        node00,
102        0f32,
103        layout.scroll_height()
104    );
105    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
106    let layout @ Layout { size, location, .. } = taffy.layout(node000).unwrap();
107    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node000, 0f32, size.width);
108    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node000, 0f32, size.height);
109    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
110    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
111    #[cfg(feature = "content_size")]
112    assert_eq!(
113        layout.scroll_width(),
114        0f32,
115        "scroll_width of node {:?}. Expected {}. Actual {}",
116        node000,
117        0f32,
118        layout.scroll_width()
119    );
120    #[cfg(feature = "content_size")]
121    assert_eq!(
122        layout.scroll_height(),
123        0f32,
124        "scroll_height of node {:?}. Expected {}. Actual {}",
125        node000,
126        0f32,
127        layout.scroll_height()
128    );
129}