gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/wrap_row.rs Rust · 176 líneas · 6.9 KB Historia Quién tocó qué crudo

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

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