gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 238TOML 3CSS 11131 Definitions

⎇ 477ff4aff498cbae4cdfbf0cda1ee5b04c784f08 tests/generated/flex/relative_position_should_not_nudge_siblings.rs Rust · 119 lines · 4.7 KB History Who touched what raw

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

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