gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Definiciones

⎇ 0.5.x tests/generated/flex/rounding_fractial_input_2.rs Rust · 141 líneas · 5.7 KB Historia Quién tocó qué crudo

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

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