tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ morphorm tests/generated/grid/grid_auto_columns.rs Rust · 81 líneas · 6.1 KB Historia Quién tocó qué crudo

Replace per-node measure functions with a single measure function + per-node context (#490) be627e7fa · Nico Burns ·

1#[test]
2fn grid_auto_columns() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, Taffy};
5    let mut taffy: Taffy<crate::TextMeasure> = Taffy::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            grid_column: taffy::geometry::Line { start: line(-3i16), end: taffy::style::GridPlacement::Auto },
9            ..Default::default()
10        })
11        .unwrap();
12    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
13    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
14    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
15    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
16    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
17    let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18    let node7 = 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![length(100f32)],
24                grid_template_columns: vec![length(40f32)],
25                grid_auto_columns: vec![length(10f32), length(20f32), length(30f32)],
26                grid_auto_flow: taffy::style::GridAutoFlow::Column,
27                ..Default::default()
28            },
29            &[node0, node1, node2, node3, node4, node5, node6, node7],
30        )
31        .unwrap();
32    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
33    println!("\nComputed tree:");
34    taffy.print_tree(node);
35    println!();
36    let Layout { size, location, .. } = taffy.layout(node).unwrap();
37    assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node, 190f32, size.width);
38    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
39    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
40    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
41    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
42    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width);
43    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
44    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
45    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
46    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
47    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
48    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
49    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
51    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
52    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node2, 10f32, size.width);
53    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
54    assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node2, 70f32, location.x);
55    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
56    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
57    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
58    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node3, 100f32, size.height);
59    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node3, 80f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
61    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
62    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node4, 30f32, size.width);
63    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node4, 100f32, size.height);
64    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node4, 100f32, location.x);
65    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node4, 0f32, location.y);
66    let Layout { size, location, .. } = taffy.layout(node5).unwrap();
67    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node5, 10f32, size.width);
68    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node5, 100f32, size.height);
69    assert_eq!(location.x, 130f32, "x of node {:?}. Expected {}. Actual {}", node5, 130f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node5, 0f32, location.y);
71    let Layout { size, location, .. } = taffy.layout(node6).unwrap();
72    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node6, 20f32, size.width);
73    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node6, 100f32, size.height);
74    assert_eq!(location.x, 140f32, "x of node {:?}. Expected {}. Actual {}", node6, 140f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node6, 0f32, location.y);
76    let Layout { size, location, .. } = taffy.layout(node7).unwrap();
77    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node7, 30f32, size.width);
78    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node7, 100f32, size.height);
79    assert_eq!(location.x, 160f32, "x of node {:?}. Expected {}. Actual {}", node7, 160f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node7, 0f32, location.y);
81}