gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/align_self_center_undefined_max_height.rs Rust · 120 siq'ikuna · 6.2 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 align_self_center_undefined_max_height__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            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(240f32),
11                height: taffy::style::Dimension::from_length(44f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node1 = taffy
17        .new_leaf(taffy::style::Style {
18            align_self: Some(taffy::style::AlignSelf::Center),
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::from_length(40f32),
21                height: taffy::style::Dimension::from_length(56f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node = taffy
27        .new_with_children(
28            taffy::style::Style {
29                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(280f32), height: auto() },
30                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(52f32) },
31                ..Default::default()
32            },
33            &[node0, node1],
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, 280f32, "width of node {:?}. Expected {}. Actual {}", node, 280f32, size.width);
43    assert_eq!(size.height, 56f32, "height of node {:?}. Expected {}. Actual {}", node, 56f32, 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, 240f32, "width of node {:?}. Expected {}. Actual {}", node0, 240f32, size.width);
49    assert_eq!(size.height, 44f32, "height of node {:?}. Expected {}. Actual {}", node0, 44f32, 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, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
55    assert_eq!(size.height, 56f32, "height of node {:?}. Expected {}. Actual {}", node1, 56f32, size.height);
56    assert_eq!(location.x, 240f32, "x of node {:?}. Expected {}. Actual {}", node1, 240f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
58}
59
60#[test]
61#[allow(non_snake_case)]
62fn align_self_center_undefined_max_height__content_box() {
63    #[allow(unused_imports)]
64    use taffy::{prelude::*, Layout};
65    let mut taffy = crate::new_test_tree();
66    let node0 = taffy
67        .new_leaf(taffy::style::Style {
68            box_sizing: taffy::style::BoxSizing::ContentBox,
69            size: taffy::geometry::Size {
70                width: taffy::style::Dimension::from_length(240f32),
71                height: taffy::style::Dimension::from_length(44f32),
72            },
73            ..Default::default()
74        })
75        .unwrap();
76    let node1 = taffy
77        .new_leaf(taffy::style::Style {
78            box_sizing: taffy::style::BoxSizing::ContentBox,
79            align_self: Some(taffy::style::AlignSelf::Center),
80            size: taffy::geometry::Size {
81                width: taffy::style::Dimension::from_length(40f32),
82                height: taffy::style::Dimension::from_length(56f32),
83            },
84            ..Default::default()
85        })
86        .unwrap();
87    let node = taffy
88        .new_with_children(
89            taffy::style::Style {
90                box_sizing: taffy::style::BoxSizing::ContentBox,
91                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(280f32), height: auto() },
92                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(52f32) },
93                ..Default::default()
94            },
95            &[node0, node1],
96        )
97        .unwrap();
98    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
99    println!("\nComputed tree:");
100    taffy.print_tree(node);
101    println!();
102    let layout = taffy.layout(node).unwrap();
103    let Layout { size, location, .. } = layout;
104    assert_eq!(size.width, 280f32, "width of node {:?}. Expected {}. Actual {}", node, 280f32, size.width);
105    assert_eq!(size.height, 56f32, "height of node {:?}. Expected {}. Actual {}", node, 56f32, size.height);
106    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
107    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
108    let layout = taffy.layout(node0).unwrap();
109    let Layout { size, location, .. } = layout;
110    assert_eq!(size.width, 240f32, "width of node {:?}. Expected {}. Actual {}", node0, 240f32, size.width);
111    assert_eq!(size.height, 44f32, "height of node {:?}. Expected {}. Actual {}", node0, 44f32, size.height);
112    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
113    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
114    let layout = taffy.layout(node1).unwrap();
115    let Layout { size, location, .. } = layout;
116    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
117    assert_eq!(size.height, 56f32, "height of node {:?}. Expected {}. Actual {}", node1, 56f32, size.height);
118    assert_eq!(location.x, 240f32, "x of node {:?}. Expected {}. Actual {}", node1, 240f32, location.x);
119    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
120}