gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ 01babab32d8138f3c3fa05095fb6c65fca0d3967 tests/generated/grid_absolute_column_start.rs Rust · 54 líneas · 2.8 KB Historia Quién tocó qué crudo

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

1#[test]
2fn grid_absolute_column_start() {
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            position_type: taffy::style::PositionType::Absolute,
10            grid_column: taffy::geometry::Line {
11                start: taffy::style::GridPlacement::Line(1i16),
12                end: taffy::style::GridPlacement::Auto,
13            },
14            position: taffy::geometry::Rect {
15                left: taffy::style::LengthPercentageAuto::Points(4f32),
16                right: taffy::style::LengthPercentageAuto::Points(3f32),
17                top: taffy::style::LengthPercentageAuto::Points(1f32),
18                bottom: taffy::style::LengthPercentageAuto::Points(2f32),
19            },
20            ..Default::default()
21        })
22        .unwrap();
23    let node = taffy
24        .new_with_children(
25            taffy::style::Style {
26                display: taffy::style::Display::Grid,
27                grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
28                grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
29                padding: taffy::geometry::Rect {
30                    left: taffy::style::LengthPercentage::Points(40f32),
31                    right: taffy::style::LengthPercentage::Points(20f32),
32                    top: taffy::style::LengthPercentage::Points(10f32),
33                    bottom: taffy::style::LengthPercentage::Points(30f32),
34                },
35                ..Default::default()
36            },
37            &[node0],
38        )
39        .unwrap();
40    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
41    println!("\nComputed tree:");
42    taffy::debug::print_tree(&taffy, node);
43    println!();
44    let Layout { size, location, .. } = taffy.layout(node).unwrap();
45    assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 180f32, size.width);
46    assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 160f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
48    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
49    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
50    assert_eq!(size.width, 133f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 133f32, size.width);
51    assert_eq!(size.height, 157f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 157f32, size.height);
52    assert_eq!(location.x, 44f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 44f32, location.x);
53    assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 1f32, location.y);
54}