gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/bevy_issue_7976_4_level.rs Rust · 162 líneas · 6.8 KB Historia Quién tocó qué crudo

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

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