gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 498HTML 254C 19JavaScript 81339 Definiciones

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

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

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