gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 976HTML 921Markdown 12TOML 82979 Sutichaykuna

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/relative_position_should_not_nudge_siblings.rs Rust · 63 siq'ikuna · 3.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename PositionType and Position in accordance to specs (#295) e2cee9d6f · Andreas Weibye ·

1#[test]
2fn relative_position_should_not_nudge_siblings() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(10f32) },
10            inset: taffy::geometry::Rect {
11                left: auto(),
12                right: auto(),
13                top: taffy::style::LengthPercentageAuto::Points(15f32),
14                bottom: auto(),
15            },
16            ..Default::default()
17        })
18        .unwrap();
19    let node1 = taffy
20        .new_leaf(taffy::style::Style {
21            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(10f32) },
22            inset: taffy::geometry::Rect {
23                left: auto(),
24                right: auto(),
25                top: taffy::style::LengthPercentageAuto::Points(15f32),
26                bottom: auto(),
27            },
28            ..Default::default()
29        })
30        .unwrap();
31    let node = taffy
32        .new_with_children(
33            taffy::style::Style {
34                flex_direction: taffy::style::FlexDirection::Column,
35                size: taffy::geometry::Size {
36                    width: taffy::style::Dimension::Points(100f32),
37                    height: taffy::style::Dimension::Points(100f32),
38                },
39                ..Default::default()
40            },
41            &[node0, node1],
42        )
43        .unwrap();
44    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
45    println!("\nComputed tree:");
46    taffy::debug::print_tree(&taffy, node);
47    println!();
48    let Layout { size, location, .. } = taffy.layout(node).unwrap();
49    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
50    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
51    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
52    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
53    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
54    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
55    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
57    assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y);
58    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
59    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, size.width);
60    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 10f32, size.height);
61    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
62    assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 25f32, location.y);
63}