gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 89Markdown 11TOML 91930 Sutichaykuna

⎇ 0.1.x tests/relayout.rs Rust · 63 siq'ikuna · 2.1 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1use taffy::style::Dimension;
2
3#[test]
4fn relayout() {
5    let mut taffy = taffy::Taffy::new();
6    let node1 = taffy
7        .new_node(
8            taffy::style::Style {
9                size: taffy::geometry::Size { width: Dimension::Points(8f32), height: Dimension::Points(80f32) },
10                ..Default::default()
11            },
12            &[],
13        )
14        .unwrap();
15    let node0 = taffy
16        .new_node(
17            taffy::style::Style {
18                align_self: taffy::prelude::AlignSelf::Center,
19                size: taffy::geometry::Size { width: Dimension::Auto, height: Dimension::Auto },
20                // size: taffy::geometry::Size { width: Dimension::Percent(1.0), height: Dimension::Percent(1.0) },
21                ..Default::default()
22            },
23            &[node1],
24        )
25        .unwrap();
26    let node = taffy
27        .new_node(
28            taffy::style::Style {
29                size: taffy::geometry::Size { width: Dimension::Percent(1f32), height: Dimension::Percent(1f32) },
30                ..Default::default()
31            },
32            &[node0],
33        )
34        .unwrap();
35    println!("0:");
36    taffy
37        .compute_layout(
38            node,
39            taffy::geometry::Size {
40                width: taffy::prelude::Number::Defined(100f32),
41                height: taffy::prelude::Number::Defined(100f32),
42            },
43        )
44        .unwrap();
45    let initial = taffy.layout(node).unwrap().location;
46    let initial0 = taffy.layout(node0).unwrap().location;
47    let initial1 = taffy.layout(node1).unwrap().location;
48    for i in 1..10 {
49        println!("\n\n{i}:");
50        taffy
51            .compute_layout(
52                node,
53                taffy::geometry::Size {
54                    width: taffy::prelude::Number::Defined(100f32),
55                    height: taffy::prelude::Number::Defined(100f32),
56                },
57            )
58            .unwrap();
59        assert_eq!(taffy.layout(node).unwrap().location, initial);
60        assert_eq!(taffy.layout(node0).unwrap().location, initial0);
61        assert_eq!(taffy.layout(node1).unwrap().location, initial1);
62    }
63}