gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Definiciones

⎇ 0.1.x tests/generated/margin_auto_left.rs Rust · 58 líneas · 2.3 KB Historia Quién tocó qué crudo

Rename sprawl to taffy (#134) 8936790d6 · Alice Cecile ·

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