tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Sutichaykuna

⎇ float-layout tests/generated/grid/grid_absolute_column_end.rs Rust · 109 siq'ikuna · 5.1 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_absolute_column_end__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            position: taffy::style::Position::Absolute,
10            grid_column: taffy::geometry::Line { start: taffy::style::GridPlacement::Auto, end: line(1i16) },
11            inset: taffy::geometry::Rect {
12                left: length(4f32),
13                right: length(3f32),
14                top: length(1f32),
15                bottom: length(2f32),
16            },
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), length(40f32)],
25                grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
26                padding: taffy::geometry::Rect {
27                    left: length(40f32),
28                    right: length(20f32),
29                    top: length(10f32),
30                    bottom: length(30f32),
31                },
32                ..Default::default()
33            },
34            &[node0],
35        )
36        .unwrap();
37    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
38    println!("\nComputed tree:");
39    taffy.print_tree(node);
40    println!();
41    let layout = taffy.layout(node).unwrap();
42    let Layout { size, location, .. } = layout;
43    assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
44    assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node, 160f32, size.height);
45    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
46    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
47    let layout = taffy.layout(node0).unwrap();
48    let Layout { size, location, .. } = layout;
49    assert_eq!(size.width, 33f32, "width of node {:?}. Expected {}. Actual {}", node0, 33f32, size.width);
50    assert_eq!(size.height, 157f32, "height of node {:?}. Expected {}. Actual {}", node0, 157f32, size.height);
51    assert_eq!(location.x, 4f32, "x of node {:?}. Expected {}. Actual {}", node0, 4f32, location.x);
52    assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node0, 1f32, location.y);
53}
54
55#[test]
56#[allow(non_snake_case)]
57fn grid_absolute_column_end__content_box() {
58    #[allow(unused_imports)]
59    use taffy::{prelude::*, Layout};
60    let mut taffy = crate::new_test_tree();
61    let node0 = taffy
62        .new_leaf(taffy::style::Style {
63            box_sizing: taffy::style::BoxSizing::ContentBox,
64            position: taffy::style::Position::Absolute,
65            grid_column: taffy::geometry::Line { start: taffy::style::GridPlacement::Auto, end: line(1i16) },
66            inset: taffy::geometry::Rect {
67                left: length(4f32),
68                right: length(3f32),
69                top: length(1f32),
70                bottom: length(2f32),
71            },
72            ..Default::default()
73        })
74        .unwrap();
75    let node = taffy
76        .new_with_children(
77            taffy::style::Style {
78                display: taffy::style::Display::Grid,
79                box_sizing: taffy::style::BoxSizing::ContentBox,
80                grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
81                grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
82                padding: taffy::geometry::Rect {
83                    left: length(40f32),
84                    right: length(20f32),
85                    top: length(10f32),
86                    bottom: length(30f32),
87                },
88                ..Default::default()
89            },
90            &[node0],
91        )
92        .unwrap();
93    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
94    println!("\nComputed tree:");
95    taffy.print_tree(node);
96    println!();
97    let layout = taffy.layout(node).unwrap();
98    let Layout { size, location, .. } = layout;
99    assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
100    assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node, 160f32, size.height);
101    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
102    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
103    let layout = taffy.layout(node0).unwrap();
104    let Layout { size, location, .. } = layout;
105    assert_eq!(size.width, 33f32, "width of node {:?}. Expected {}. Actual {}", node0, 33f32, size.width);
106    assert_eq!(size.height, 157f32, "height of node {:?}. Expected {}. Actual {}", node0, 157f32, size.height);
107    assert_eq!(location.x, 4f32, "x of node {:?}. Expected {}. Actual {}", node0, 4f32, location.x);
108    assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node0, 1f32, location.y);
109}