tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Sutichaykuna

⎇ fd9112585b697975a342fdb76ca5b263a2b62891 tests/generated/block/block_margin_x_fixed_auto_left.rs Rust · 113 siq'ikuna · 4.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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