tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1100HTML 1031Markdown 12TOML 84455 Definiciones

⎇ 0.7.x tests/generated/grid/grid_placement_auto_negative.rs Rust · 134 líneas · 7.5 KB Historia Quién tocó qué crudo

Add `taffy_test_helpers` crate (#755) 2a3e8476b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_placement_auto_negative__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
10            grid_column: taffy::geometry::Line { start: line(-5i16), end: taffy::style::GridPlacement::Auto },
11            ..Default::default()
12        })
13        .unwrap();
14    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
15    let node2 = taffy
16        .new_leaf(taffy::style::Style {
17            grid_row: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
18            ..Default::default()
19        })
20        .unwrap();
21    let node = taffy
22        .new_with_children(
23            taffy::style::Style {
24                display: taffy::style::Display::Grid,
25                grid_template_rows: vec![length(40f32), length(40f32)],
26                grid_template_columns: vec![length(40f32), length(40f32)],
27                size: taffy::geometry::Size {
28                    width: taffy::style::Dimension::Length(120f32),
29                    height: taffy::style::Dimension::Length(120f32),
30                },
31                ..Default::default()
32            },
33            &[node0, node1, node2],
34        )
35        .unwrap();
36    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37    println!("\nComputed tree:");
38    taffy.print_tree(node);
39    println!();
40    let layout = taffy.layout(node).unwrap();
41    let Layout { size, location, .. } = layout;
42    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
43    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
44    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
45    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
46    let layout = taffy.layout(node0).unwrap();
47    let Layout { size, location, .. } = layout;
48    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
49    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
52    let layout = taffy.layout(node1).unwrap();
53    let Layout { size, location, .. } = layout;
54    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
55    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
56    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node1, 20f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
58    let layout = taffy.layout(node2).unwrap();
59    let Layout { size, location, .. } = layout;
60    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
61    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
62    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
63    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node2, 40f32, location.y);
64}
65
66#[test]
67#[allow(non_snake_case)]
68fn grid_placement_auto_negative__content_box() {
69    #[allow(unused_imports)]
70    use taffy::{prelude::*, Layout};
71    let mut taffy = crate::new_test_tree();
72    let node0 = taffy
73        .new_leaf(taffy::style::Style {
74            box_sizing: taffy::style::BoxSizing::ContentBox,
75            grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
76            grid_column: taffy::geometry::Line { start: line(-5i16), end: taffy::style::GridPlacement::Auto },
77            ..Default::default()
78        })
79        .unwrap();
80    let node1 = taffy
81        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
82        .unwrap();
83    let node2 = taffy
84        .new_leaf(taffy::style::Style {
85            box_sizing: taffy::style::BoxSizing::ContentBox,
86            grid_row: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
87            ..Default::default()
88        })
89        .unwrap();
90    let node = taffy
91        .new_with_children(
92            taffy::style::Style {
93                display: taffy::style::Display::Grid,
94                box_sizing: taffy::style::BoxSizing::ContentBox,
95                grid_template_rows: vec![length(40f32), length(40f32)],
96                grid_template_columns: vec![length(40f32), length(40f32)],
97                size: taffy::geometry::Size {
98                    width: taffy::style::Dimension::Length(120f32),
99                    height: taffy::style::Dimension::Length(120f32),
100                },
101                ..Default::default()
102            },
103            &[node0, node1, node2],
104        )
105        .unwrap();
106    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
107    println!("\nComputed tree:");
108    taffy.print_tree(node);
109    println!();
110    let layout = taffy.layout(node).unwrap();
111    let Layout { size, location, .. } = layout;
112    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
113    assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
114    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
115    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
116    let layout = taffy.layout(node0).unwrap();
117    let Layout { size, location, .. } = layout;
118    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
119    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
120    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
121    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
122    let layout = taffy.layout(node1).unwrap();
123    let Layout { size, location, .. } = layout;
124    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
125    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
126    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node1, 20f32, location.x);
127    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
128    let layout = taffy.layout(node2).unwrap();
129    let Layout { size, location, .. } = layout;
130    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
131    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2, 40f32, size.height);
132    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
133    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node2, 40f32, location.y);
134}