gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Sutichaykuna

⎇ ff468a44f3d06dab34cd27c16cb65f9a8a784fb4 tests/generated/block/block_absolute_child_with_margin_y.rs Rust · 167 siq'ikuna · 6.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn block_absolute_child_with_margin_y() {
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            position: taffy::style::Position::Absolute,
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(9f32),
11                height: taffy::style::Dimension::Length(9f32),
12            },
13            margin: taffy::geometry::Rect {
14                left: zero(),
15                right: zero(),
16                top: taffy::style::LengthPercentageAuto::Length(7f32),
17                bottom: zero(),
18            },
19            ..Default::default()
20        })
21        .unwrap();
22    let node1 = taffy
23        .new_leaf(taffy::style::Style {
24            position: taffy::style::Position::Absolute,
25            size: taffy::geometry::Size {
26                width: taffy::style::Dimension::Length(9f32),
27                height: taffy::style::Dimension::Length(9f32),
28            },
29            margin: taffy::geometry::Rect {
30                left: zero(),
31                right: zero(),
32                top: zero(),
33                bottom: taffy::style::LengthPercentageAuto::Length(7f32),
34            },
35            ..Default::default()
36        })
37        .unwrap();
38    let node2 = taffy
39        .new_leaf(taffy::style::Style {
40            position: taffy::style::Position::Absolute,
41            size: taffy::geometry::Size {
42                width: taffy::style::Dimension::Length(9f32),
43                height: taffy::style::Dimension::Length(9f32),
44            },
45            margin: taffy::geometry::Rect {
46                left: zero(),
47                right: zero(),
48                top: taffy::style::LengthPercentageAuto::Length(10f32),
49                bottom: taffy::style::LengthPercentageAuto::Length(5f32),
50            },
51            ..Default::default()
52        })
53        .unwrap();
54    let node = taffy
55        .new_with_children(
56            taffy::style::Style {
57                display: taffy::style::Display::Block,
58                size: taffy::geometry::Size {
59                    width: taffy::style::Dimension::Length(20f32),
60                    height: taffy::style::Dimension::Length(37f32),
61                },
62                ..Default::default()
63            },
64            &[node0, node1, node2],
65        )
66        .unwrap();
67    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
68    println!("\nComputed tree:");
69    taffy.print_tree(node);
70    println!();
71    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
72    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
73    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
74    assert_eq!(size.height, 37f32, "height of node {:?}. Expected {}. Actual {}", node, 37f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
77    #[cfg(feature = "content_size")]
78    assert_eq!(
79        layout.scroll_width(),
80        0f32,
81        "scroll_width of node {:?}. Expected {}. Actual {}",
82        node,
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        node,
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(node0).unwrap();
97    assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node0, 9f32, size.width);
98    assert_eq!(size.height, 9f32, "height of node {:?}. Expected {}. Actual {}", node0, 9f32, size.height);
99    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
100    assert_eq!(location.y, 7f32, "y of node {:?}. Expected {}. Actual {}", node0, 7f32, location.y);
101    #[cfg(feature = "content_size")]
102    assert_eq!(
103        layout.scroll_width(),
104        0f32,
105        "scroll_width of node {:?}. Expected {}. Actual {}",
106        node0,
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        node0,
116        0f32,
117        layout.scroll_height()
118    );
119    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
120    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
121    assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node1, 9f32, size.width);
122    assert_eq!(size.height, 9f32, "height of node {:?}. Expected {}. Actual {}", node1, 9f32, size.height);
123    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
124    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
125    #[cfg(feature = "content_size")]
126    assert_eq!(
127        layout.scroll_width(),
128        0f32,
129        "scroll_width of node {:?}. Expected {}. Actual {}",
130        node1,
131        0f32,
132        layout.scroll_width()
133    );
134    #[cfg(feature = "content_size")]
135    assert_eq!(
136        layout.scroll_height(),
137        0f32,
138        "scroll_height of node {:?}. Expected {}. Actual {}",
139        node1,
140        0f32,
141        layout.scroll_height()
142    );
143    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
144    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
145    assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node2, 9f32, size.width);
146    assert_eq!(size.height, 9f32, "height of node {:?}. Expected {}. Actual {}", node2, 9f32, size.height);
147    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
148    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node2, 10f32, location.y);
149    #[cfg(feature = "content_size")]
150    assert_eq!(
151        layout.scroll_width(),
152        0f32,
153        "scroll_width of node {:?}. Expected {}. Actual {}",
154        node2,
155        0f32,
156        layout.scroll_width()
157    );
158    #[cfg(feature = "content_size")]
159    assert_eq!(
160        layout.scroll_height(),
161        0f32,
162        "scroll_height of node {:?}. Expected {}. Actual {}",
163        node2,
164        0f32,
165        layout.scroll_height()
166    );
167}