tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definiciones

⎇ ae87fd0283feff32a5ceffe4c77394ff6ca88d39 tests/generated/grid_fr_span_2_proportion.rs Rust · 54 líneas · 3.3 KB Historia Quién tocó qué crudo

Grid: Rename Flex to Fraction (#350) 71027a8de · Nico Burns ·

1#[test]
2fn grid_fr_span_2_proportion() {
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            grid_column: taffy::geometry::Line {
10                start: taffy::style::GridPlacement::Span(2u16),
11                end: taffy::style::GridPlacement::Auto,
12            },
13            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), height: auto() },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19    let node = taffy
20        .new_with_children(
21            taffy::style::Style {
22                display: taffy::style::Display::Grid,
23                grid_template_rows: vec![points(40f32), points(40f32)],
24                grid_template_columns: vec![fr(1f32), fr(2f32)],
25                ..Default::default()
26            },
27            &[node0, node1, node2],
28        )
29        .unwrap();
30    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
31    println!("\nComputed tree:");
32    taffy::debug::print_tree(&taffy, node);
33    println!();
34    let Layout { size, location, .. } = taffy.layout(node).unwrap();
35    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 60f32, size.width);
36    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 80f32, size.height);
37    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
38    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
39    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
40    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.width);
41    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
42    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
43    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
44    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
45    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.width);
46    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
48    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y);
49    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
50    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 40f32, size.width);
51    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 40f32, size.height);
52    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, location.x);
53    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 40f32, location.y);
54}