gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

⎇ c9c40576df24056c2f0f8b421d8046d33bb1cc2d tests/generated/grid/grid_placement_auto_negative.rs Rust · 59 lines · 3.5 KB History Who touched what raw

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

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