tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1118HTML 1044Markdown 12TOML 94787 Definitions

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/relative_position_should_not_nudge_siblings.rs Rust · 116 lines · 6.3 KB History Who touched what raw

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

1#[test]
2#[allow(non_snake_case)]
3fn relative_position_should_not_nudge_siblings__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 { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
10            inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(15f32), bottom: auto() },
11            ..Default::default()
12        })
13        .unwrap();
14    let node1 = taffy
15        .new_leaf(taffy::style::Style {
16            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
17            inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(15f32), bottom: auto() },
18            ..Default::default()
19        })
20        .unwrap();
21    let node = taffy
22        .new_with_children(
23            taffy::style::Style {
24                flex_direction: taffy::style::FlexDirection::Column,
25                size: taffy::geometry::Size {
26                    width: taffy::style::Dimension::from_length(100f32),
27                    height: taffy::style::Dimension::from_length(100f32),
28                },
29                ..Default::default()
30            },
31            &[node0, node1],
32        )
33        .unwrap();
34    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
35    println!("\nComputed tree:");
36    taffy.print_tree(node);
37    println!();
38    let layout = taffy.layout(node).unwrap();
39    let Layout { size, location, .. } = layout;
40    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
41    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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 = taffy.layout(node0).unwrap();
45    let Layout { size, location, .. } = layout;
46    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
47    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
48    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
49    assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0, 15f32, location.y);
50    let layout = taffy.layout(node1).unwrap();
51    let Layout { size, location, .. } = layout;
52    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
53    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
55    assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node1, 25f32, location.y);
56}
57
58#[test]
59#[allow(non_snake_case)]
60fn relative_position_should_not_nudge_siblings__content_box() {
61    #[allow(unused_imports)]
62    use taffy::{prelude::*, Layout};
63    let mut taffy = crate::new_test_tree();
64    let node0 = taffy
65        .new_leaf(taffy::style::Style {
66            box_sizing: taffy::style::BoxSizing::ContentBox,
67            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
68            inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(15f32), bottom: auto() },
69            ..Default::default()
70        })
71        .unwrap();
72    let node1 = taffy
73        .new_leaf(taffy::style::Style {
74            box_sizing: taffy::style::BoxSizing::ContentBox,
75            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
76            inset: taffy::geometry::Rect { left: auto(), right: auto(), top: length(15f32), bottom: auto() },
77            ..Default::default()
78        })
79        .unwrap();
80    let node = taffy
81        .new_with_children(
82            taffy::style::Style {
83                box_sizing: taffy::style::BoxSizing::ContentBox,
84                flex_direction: taffy::style::FlexDirection::Column,
85                size: taffy::geometry::Size {
86                    width: taffy::style::Dimension::from_length(100f32),
87                    height: taffy::style::Dimension::from_length(100f32),
88                },
89                ..Default::default()
90            },
91            &[node0, node1],
92        )
93        .unwrap();
94    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
95    println!("\nComputed tree:");
96    taffy.print_tree(node);
97    println!();
98    let layout = taffy.layout(node).unwrap();
99    let Layout { size, location, .. } = layout;
100    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
101    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
102    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
103    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
104    let layout = taffy.layout(node0).unwrap();
105    let Layout { size, location, .. } = layout;
106    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
107    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
108    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
109    assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0, 15f32, location.y);
110    let layout = taffy.layout(node1).unwrap();
111    let Layout { size, location, .. } = layout;
112    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
113    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
114    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
115    assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node1, 25f32, location.y);
116}