tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91841 Definiciones

⎇ b1ea6794519524c818057af327f78c09ff379453 tests/relayout.rs Rust · 47 líneas · 1.8 KB Historia Quién tocó qué crudo

Replace Number type with a simpler Option<f32> (#144) b1ea67945 · Alice Cecile ·

1use taffy::style::Dimension;
2
3#[test]
4fn relayout() {
5    let mut taffy = taffy::Taffy::new();
6    let node1 = taffy
7        .new_with_children(
8            taffy::style::FlexboxLayout {
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_with_children(
17            taffy::style::FlexboxLayout {
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_with_children(
28            taffy::style::FlexboxLayout {
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.compute_layout(node, taffy::geometry::Size { width: Some(100f32), height: Some(100f32) }).unwrap();
37    let initial = taffy.layout(node).unwrap().location;
38    let initial0 = taffy.layout(node0).unwrap().location;
39    let initial1 = taffy.layout(node1).unwrap().location;
40    for i in 1..10 {
41        println!("\n\n{i}:");
42        taffy.compute_layout(node, taffy::geometry::Size { width: Some(100f32), height: Some(100f32) }).unwrap();
43        assert_eq!(taffy.layout(node).unwrap().location, initial);
44        assert_eq!(taffy.layout(node0).unwrap().location, initial0);
45        assert_eq!(taffy.layout(node1).unwrap().location, initial1);
46    }
47}