gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Definiciones

⎇ 0.3.x tests/generated/percent_within_flex_grow.rs Rust · 76 líneas · 4.2 KB Historia Quién tocó qué crudo

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

1#[test]
2fn percent_within_flex_grow() {
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            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: auto() },
10            ..Default::default()
11        })
12        .unwrap();
13    let node10 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: auto() },
16            ..Default::default()
17        })
18        .unwrap();
19    let node1 = taffy
20        .new_with_children(
21            taffy::style::Style {
22                flex_direction: taffy::style::FlexDirection::Column,
23                flex_grow: 1f32,
24                ..Default::default()
25            },
26            &[node10],
27        )
28        .unwrap();
29    let node2 = taffy
30        .new_leaf(taffy::style::Style {
31            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: auto() },
32            ..Default::default()
33        })
34        .unwrap();
35    let node = taffy
36        .new_with_children(
37            taffy::style::Style {
38                size: taffy::geometry::Size {
39                    width: taffy::style::Dimension::Points(350f32),
40                    height: taffy::style::Dimension::Points(100f32),
41                },
42                ..Default::default()
43            },
44            &[node0, node1, node2],
45        )
46        .unwrap();
47    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
48    println!("\nComputed tree:");
49    taffy::debug::print_tree(&taffy, node);
50    println!();
51    let Layout { size, location, .. } = taffy.layout(node).unwrap();
52    assert_eq!(size.width, 350f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 350f32, size.width);
53    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
55    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
56    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
57    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
58    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
61    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
62    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 150f32, size.width);
63    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, size.height);
64    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, location.x);
65    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
66    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
67    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 150f32, size.width);
68    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
71    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
72    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, size.width);
73    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, size.height);
74    assert_eq!(location.x, 250f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 250f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
76}