gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 498HTML 254C 19JavaScript 81339 Definiciones

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

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

1#[test]
2fn flex_grow_less_than_factor_one() {
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: 0.2f32,
9            flex_shrink: 0f32,
10            flex_basis: taffy::style::Dimension::Length(40f32),
11            ..Default::default()
12        })
13        .unwrap();
14    let node1 =
15        taffy.new_leaf(taffy::style::Style { flex_grow: 0.2f32, flex_shrink: 0f32, ..Default::default() }).unwrap();
16    let node2 =
17        taffy.new_leaf(taffy::style::Style { flex_grow: 0.4f32, flex_shrink: 0f32, ..Default::default() }).unwrap();
18    let node = taffy
19        .new_with_children(
20            taffy::style::Style {
21                size: taffy::geometry::Size {
22                    width: taffy::style::Dimension::Length(500f32),
23                    height: taffy::style::Dimension::Length(200f32),
24                },
25                ..Default::default()
26            },
27            &[node0, node1, node2],
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, 500f32, "width of node {:?}. Expected {}. Actual {}", node, 500f32, size.width);
37    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, 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, 132f32, "width of node {:?}. Expected {}. Actual {}", node0, 132f32, size.width);
61    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node0, 200f32, 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, 92f32, "width of node {:?}. Expected {}. Actual {}", node1, 92f32, size.width);
85    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node1, 200f32, size.height);
86    assert_eq!(location.x, 132f32, "x of node {:?}. Expected {}. Actual {}", node1, 132f32, location.x);
87    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, 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    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
107    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
108    assert_eq!(size.width, 184f32, "width of node {:?}. Expected {}. Actual {}", node2, 184f32, size.width);
109    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node2, 200f32, size.height);
110    assert_eq!(location.x, 224f32, "x of node {:?}. Expected {}. Actual {}", node2, 224f32, location.x);
111    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
112    #[cfg(feature = "content_size")]
113    assert_eq!(
114        layout.scroll_width(),
115        0f32,
116        "scroll_width of node {:?}. Expected {}. Actual {}",
117        node2,
118        0f32,
119        layout.scroll_width()
120    );
121    #[cfg(feature = "content_size")]
122    assert_eq!(
123        layout.scroll_height(),
124        0f32,
125        "scroll_height of node {:?}. Expected {}. Actual {}",
126        node2,
127        0f32,
128        layout.scroll_height()
129    );
130}