gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94541 Sutichaykuna

⎇ 0.2.x tests/relayout.rs Rust · 58 siq'ikuna · 2.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename FlexboxLayout back to Style (#251) 49893a7d9 · Nico Burns ·

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