tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1068HTML 999Markdown 12TOML 83186 Definiciones

⎇ f1e4edab96ee13f7d1fbc2536ac31633b0e620d6 tests/generated/block/block_margin_auto_multiple_children.rs Rust · 159 líneas · 6.2 KB Historia Quién tocó qué crudo

Fix typos. (#611) f1e4edab9 · Bruce Mitchener ·

1#[test]
2fn block_margin_auto_multiple_children() {
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(100f32),
10                height: taffy::style::Dimension::Length(50f32),
11            },
12            margin: taffy::geometry::Rect {
13                left: zero(),
14                right: taffy::style::LengthPercentageAuto::Auto,
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 {
24                width: taffy::style::Dimension::Length(50f32),
25                height: taffy::style::Dimension::Length(50f32),
26            },
27            margin: taffy::geometry::Rect {
28                left: zero(),
29                right: taffy::style::LengthPercentageAuto::Auto,
30                top: zero(),
31                bottom: zero(),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node2 = taffy
37        .new_leaf(taffy::style::Style {
38            size: taffy::geometry::Size {
39                width: taffy::style::Dimension::Length(50f32),
40                height: taffy::style::Dimension::Length(50f32),
41            },
42            ..Default::default()
43        })
44        .unwrap();
45    let node = taffy
46        .new_with_children(
47            taffy::style::Style {
48                display: taffy::style::Display::Block,
49                align_items: Some(taffy::style::AlignItems::Center),
50                size: taffy::geometry::Size {
51                    width: taffy::style::Dimension::Length(200f32),
52                    height: taffy::style::Dimension::Length(200f32),
53                },
54                ..Default::default()
55            },
56            &[node0, node1, node2],
57        )
58        .unwrap();
59    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
60    println!("\nComputed tree:");
61    taffy.print_tree(node);
62    println!();
63    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
64    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
65    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
66    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
67    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
68    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
69    #[cfg(feature = "content_size")]
70    assert_eq!(
71        layout.scroll_width(),
72        0f32,
73        "scroll_width of node {:?}. Expected {}. Actual {}",
74        node,
75        0f32,
76        layout.scroll_width()
77    );
78    #[cfg(feature = "content_size")]
79    assert_eq!(
80        layout.scroll_height(),
81        0f32,
82        "scroll_height of node {:?}. Expected {}. Actual {}",
83        node,
84        0f32,
85        layout.scroll_height()
86    );
87    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
88    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
89    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
90    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
91    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
92    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
93    #[cfg(feature = "content_size")]
94    assert_eq!(
95        layout.scroll_width(),
96        0f32,
97        "scroll_width of node {:?}. Expected {}. Actual {}",
98        node0,
99        0f32,
100        layout.scroll_width()
101    );
102    #[cfg(feature = "content_size")]
103    assert_eq!(
104        layout.scroll_height(),
105        0f32,
106        "scroll_height of node {:?}. Expected {}. Actual {}",
107        node0,
108        0f32,
109        layout.scroll_height()
110    );
111    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
112    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
113    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
114    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
115    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
116    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
117    #[cfg(feature = "content_size")]
118    assert_eq!(
119        layout.scroll_width(),
120        0f32,
121        "scroll_width of node {:?}. Expected {}. Actual {}",
122        node1,
123        0f32,
124        layout.scroll_width()
125    );
126    #[cfg(feature = "content_size")]
127    assert_eq!(
128        layout.scroll_height(),
129        0f32,
130        "scroll_height of node {:?}. Expected {}. Actual {}",
131        node1,
132        0f32,
133        layout.scroll_height()
134    );
135    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
136    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
137    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
138    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
139    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
140    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node2, 100f32, location.y);
141    #[cfg(feature = "content_size")]
142    assert_eq!(
143        layout.scroll_width(),
144        0f32,
145        "scroll_width of node {:?}. Expected {}. Actual {}",
146        node2,
147        0f32,
148        layout.scroll_width()
149    );
150    #[cfg(feature = "content_size")]
151    assert_eq!(
152        layout.scroll_height(),
153        0f32,
154        "scroll_height of node {:?}. Expected {}. Actual {}",
155        node2,
156        0f32,
157        layout.scroll_height()
158    );
159}