tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definiciones

⎇ 6ce28e1535f2ab4631d0502f2fee13d4827f2a11 tests/relayout.rs Rust · 57 líneas · 2.0 KB Historia Quién tocó qué crudo

Implement CSS Grid (#205) 6fd2c6bcb · Nico Burns ·

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