tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Sutichaykuna

⎇ float-layout tests/generated/flex/absolute_layout_justify_content_center.rs Rust · 95 siq'ikuna · 4.6 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 absolute_layout_justify_content_center__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            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_length(60f32),
12                height: taffy::style::Dimension::from_length(40f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node = taffy
18        .new_with_children(
19            taffy::style::Style {
20                justify_content: Some(taffy::style::JustifyContent::Center),
21                size: taffy::geometry::Size {
22                    width: taffy::style::Dimension::from_length(110f32),
23                    height: taffy::style::Dimension::from_length(100f32),
24                },
25                ..Default::default()
26            },
27            &[node0],
28        )
29        .unwrap();
30    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
31    println!("\nComputed tree:");
32    taffy.print_tree(node);
33    println!();
34    let layout = taffy.layout(node).unwrap();
35    let Layout { size, location, .. } = layout;
36    assert_eq!(size.width, 110f32, "width of node {:?}. Expected {}. Actual {}", node, 110f32, size.width);
37    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
38    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
39    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
40    let layout = taffy.layout(node0).unwrap();
41    let Layout { size, location, .. } = layout;
42    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
43    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
44    assert_eq!(location.x, 25f32, "x of node {:?}. Expected {}. Actual {}", node0, 25f32, location.x);
45    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
46}
47
48#[test]
49#[allow(non_snake_case)]
50fn absolute_layout_justify_content_center__content_box() {
51    #[allow(unused_imports)]
52    use taffy::{prelude::*, Layout};
53    let mut taffy = crate::new_test_tree();
54    let node0 = taffy
55        .new_leaf(taffy::style::Style {
56            box_sizing: taffy::style::BoxSizing::ContentBox,
57            position: taffy::style::Position::Absolute,
58            size: taffy::geometry::Size {
59                width: taffy::style::Dimension::from_length(60f32),
60                height: taffy::style::Dimension::from_length(40f32),
61            },
62            ..Default::default()
63        })
64        .unwrap();
65    let node = taffy
66        .new_with_children(
67            taffy::style::Style {
68                box_sizing: taffy::style::BoxSizing::ContentBox,
69                justify_content: Some(taffy::style::JustifyContent::Center),
70                size: taffy::geometry::Size {
71                    width: taffy::style::Dimension::from_length(110f32),
72                    height: taffy::style::Dimension::from_length(100f32),
73                },
74                ..Default::default()
75            },
76            &[node0],
77        )
78        .unwrap();
79    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
80    println!("\nComputed tree:");
81    taffy.print_tree(node);
82    println!();
83    let layout = taffy.layout(node).unwrap();
84    let Layout { size, location, .. } = layout;
85    assert_eq!(size.width, 110f32, "width of node {:?}. Expected {}. Actual {}", node, 110f32, size.width);
86    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
87    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
89    let layout = taffy.layout(node0).unwrap();
90    let Layout { size, location, .. } = layout;
91    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
92    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
93    assert_eq!(location.x, 25f32, "x of node {:?}. Expected {}. Actual {}", node0, 25f32, location.x);
94    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
95}