gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 976HTML 921Markdown 12TOML 82979 Definiciones

⎇ 0.5.x tests/generated/flex/align_content_end_wrapped_negative_space_gap.rs Rust · 197 líneas · 8.1 KB Historia Quién tocó qué crudo

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

1#[test]
2fn align_content_end_wrapped_negative_space_gap() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            flex_shrink: 0f32,
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Percent(0.8f32),
11                height: taffy::style::Dimension::Length(20f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node01 = taffy
17        .new_leaf(taffy::style::Style {
18            flex_shrink: 0f32,
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::Percent(0.8f32),
21                height: taffy::style::Dimension::Length(20f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node02 = taffy
27        .new_leaf(taffy::style::Style {
28            flex_shrink: 0f32,
29            size: taffy::geometry::Size {
30                width: taffy::style::Dimension::Percent(0.8f32),
31                height: taffy::style::Dimension::Length(20f32),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node0 = taffy
37        .new_with_children(
38            taffy::style::Style {
39                display: taffy::style::Display::Flex,
40                flex_wrap: taffy::style::FlexWrap::Wrap,
41                align_content: Some(taffy::style::AlignContent::End),
42                justify_content: Some(taffy::style::JustifyContent::Center),
43                gap: taffy::geometry::Size {
44                    width: taffy::style::LengthPercentage::Length(10f32),
45                    height: taffy::style::LengthPercentage::Length(10f32),
46                },
47                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
48                ..Default::default()
49            },
50            &[node00, node01, node02],
51        )
52        .unwrap();
53    let node = taffy
54        .new_with_children(
55            taffy::style::Style {
56                display: taffy::style::Display::Flex,
57                flex_direction: taffy::style::FlexDirection::Column,
58                size: taffy::geometry::Size {
59                    width: taffy::style::Dimension::Length(320f32),
60                    height: taffy::style::Dimension::Length(320f32),
61                },
62                border: taffy::geometry::Rect {
63                    left: taffy::style::LengthPercentage::Length(60f32),
64                    right: taffy::style::LengthPercentage::Length(60f32),
65                    top: taffy::style::LengthPercentage::Length(60f32),
66                    bottom: taffy::style::LengthPercentage::Length(60f32),
67                },
68                ..Default::default()
69            },
70            &[node0],
71        )
72        .unwrap();
73    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
74    println!("\nComputed tree:");
75    taffy.print_tree(node);
76    println!();
77    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
78    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
79    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
80    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node, 320f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
82    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
83    #[cfg(feature = "content_size")]
84    assert_eq!(
85        layout.scroll_width(),
86        0f32,
87        "scroll_width of node {:?}. Expected {}. Actual {}",
88        node,
89        0f32,
90        layout.scroll_width()
91    );
92    #[cfg(feature = "content_size")]
93    assert_eq!(
94        layout.scroll_height(),
95        0f32,
96        "scroll_height of node {:?}. Expected {}. Actual {}",
97        node,
98        0f32,
99        layout.scroll_height()
100    );
101    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
102    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
103    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
104    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
105    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node0, 60f32, location.x);
106    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node0, 60f32, location.y);
107    #[cfg(feature = "content_size")]
108    assert_eq!(
109        layout.scroll_width(),
110        0f32,
111        "scroll_width of node {:?}. Expected {}. Actual {}",
112        node0,
113        0f32,
114        layout.scroll_width()
115    );
116    #[cfg(feature = "content_size")]
117    assert_eq!(
118        layout.scroll_height(),
119        0f32,
120        "scroll_height of node {:?}. Expected {}. Actual {}",
121        node0,
122        0f32,
123        layout.scroll_height()
124    );
125    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
126    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
127    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
128    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
129    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
130    assert_eq!(location.y, -70f32, "y of node {:?}. Expected {}. Actual {}", node00, -70f32, location.y);
131    #[cfg(feature = "content_size")]
132    assert_eq!(
133        layout.scroll_width(),
134        0f32,
135        "scroll_width of node {:?}. Expected {}. Actual {}",
136        node00,
137        0f32,
138        layout.scroll_width()
139    );
140    #[cfg(feature = "content_size")]
141    assert_eq!(
142        layout.scroll_height(),
143        0f32,
144        "scroll_height of node {:?}. Expected {}. Actual {}",
145        node00,
146        0f32,
147        layout.scroll_height()
148    );
149    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
150    let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
151    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node01, 160f32, size.width);
152    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
153    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
154    assert_eq!(location.y, -40f32, "y of node {:?}. Expected {}. Actual {}", node01, -40f32, location.y);
155    #[cfg(feature = "content_size")]
156    assert_eq!(
157        layout.scroll_width(),
158        0f32,
159        "scroll_width of node {:?}. Expected {}. Actual {}",
160        node01,
161        0f32,
162        layout.scroll_width()
163    );
164    #[cfg(feature = "content_size")]
165    assert_eq!(
166        layout.scroll_height(),
167        0f32,
168        "scroll_height of node {:?}. Expected {}. Actual {}",
169        node01,
170        0f32,
171        layout.scroll_height()
172    );
173    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
174    let layout @ Layout { size, location, .. } = taffy.layout(node02).unwrap();
175    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node02, 160f32, size.width);
176    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02, 20f32, size.height);
177    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node02, 20f32, location.x);
178    assert_eq!(location.y, -10f32, "y of node {:?}. Expected {}. Actual {}", node02, -10f32, location.y);
179    #[cfg(feature = "content_size")]
180    assert_eq!(
181        layout.scroll_width(),
182        0f32,
183        "scroll_width of node {:?}. Expected {}. Actual {}",
184        node02,
185        0f32,
186        layout.scroll_width()
187    );
188    #[cfg(feature = "content_size")]
189    assert_eq!(
190        layout.scroll_height(),
191        0f32,
192        "scroll_height of node {:?}. Expected {}. Actual {}",
193        node02,
194        0f32,
195        layout.scroll_height()
196    );
197}