tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definiciones

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/align_self_baseline.rs Rust · 75 líneas · 3.9 KB Historia Quién tocó qué crudo

Better assert messages (#290) 2b7d63a03 · Nico Burns ·

1#[test]
2fn align_self_baseline() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            align_self: Some(taffy::style::AlignSelf::Baseline),
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::Points(50f32),
12                height: taffy::style::Dimension::Points(50f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node10 = taffy
18        .new_leaf(taffy::style::Style {
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::Points(50f32),
21                height: taffy::style::Dimension::Points(10f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node1 = taffy
27        .new_with_children(
28            taffy::style::Style {
29                align_self: Some(taffy::style::AlignSelf::Baseline),
30                size: taffy::geometry::Size {
31                    width: taffy::style::Dimension::Points(50f32),
32                    height: taffy::style::Dimension::Points(20f32),
33                },
34                ..Default::default()
35            },
36            &[node10],
37        )
38        .unwrap();
39    let node = taffy
40        .new_with_children(
41            taffy::style::Style {
42                size: taffy::geometry::Size {
43                    width: taffy::style::Dimension::Points(100f32),
44                    height: taffy::style::Dimension::Points(100f32),
45                },
46                ..Default::default()
47            },
48            &[node0, node1],
49        )
50        .unwrap();
51    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
52    println!("\nComputed tree:");
53    taffy::debug::print_tree(&taffy, node);
54    println!();
55    let Layout { size, location, .. } = taffy.layout(node).unwrap();
56    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
57    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
58    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
59    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
60    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
61    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
62    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
63    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
64    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
65    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
66    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
67    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
68    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, location.x);
69    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y);
70    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
71    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 50f32, size.width);
72    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 10f32, size.height);
73    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
74    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
75}