gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 254C 19JavaScript 81378 Definitions

⎇ 06471455e8cc93ab7ffee650a033ae7df8943611 tests/generated/margin_auto_top.rs Rust · 58 lines · 2.4 KB History Who touched what raw

rename stretch to stretch2 99945cfc7 · elbaro ·

1#[test]
2fn margin_auto_top() {
3    let mut stretch = stretch2::Stretch::new();
4    let node0 = stretch
5        .new_node(
6            stretch2::style::Style {
7                size: stretch2::geometry::Size {
8                    width: stretch2::style::Dimension::Points(50f32),
9                    height: stretch2::style::Dimension::Points(50f32),
10                    ..Default::default()
11                },
12                margin: stretch2::geometry::Rect { top: stretch2::style::Dimension::Auto, ..Default::default() },
13                ..Default::default()
14            },
15            &[],
16        )
17        .unwrap();
18    let node1 = stretch
19        .new_node(
20            stretch2::style::Style {
21                size: stretch2::geometry::Size {
22                    width: stretch2::style::Dimension::Points(50f32),
23                    height: stretch2::style::Dimension::Points(50f32),
24                    ..Default::default()
25                },
26                ..Default::default()
27            },
28            &[],
29        )
30        .unwrap();
31    let node = stretch
32        .new_node(
33            stretch2::style::Style {
34                align_items: stretch2::style::AlignItems::Center,
35                size: stretch2::geometry::Size {
36                    width: stretch2::style::Dimension::Points(200f32),
37                    height: stretch2::style::Dimension::Points(200f32),
38                    ..Default::default()
39                },
40                ..Default::default()
41            },
42            &[node0, node1],
43        )
44        .unwrap();
45    stretch.compute_layout(node, stretch2::geometry::Size::undefined()).unwrap();
46    assert_eq!(stretch.layout(node).unwrap().size.width, 200f32);
47    assert_eq!(stretch.layout(node).unwrap().size.height, 200f32);
48    assert_eq!(stretch.layout(node).unwrap().location.x, 0f32);
49    assert_eq!(stretch.layout(node).unwrap().location.y, 0f32);
50    assert_eq!(stretch.layout(node0).unwrap().size.width, 50f32);
51    assert_eq!(stretch.layout(node0).unwrap().size.height, 50f32);
52    assert_eq!(stretch.layout(node0).unwrap().location.x, 0f32);
53    assert_eq!(stretch.layout(node0).unwrap().location.y, 150f32);
54    assert_eq!(stretch.layout(node1).unwrap().size.width, 50f32);
55    assert_eq!(stretch.layout(node1).unwrap().size.height, 50f32);
56    assert_eq!(stretch.layout(node1).unwrap().location.x, 50f32);
57    assert_eq!(stretch.layout(node1).unwrap().location.y, 75f32);
58}