tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1350 Definiciones

⎇ cd73db35cfa2b31555a796e7972cd97a45554e17 tests/generated/flex/wrap_reverse_column.rs Rust · 180 líneas · 7.1 KB Historia Quién tocó qué crudo

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

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