gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 701HTML 654Markdown 12TOML 62332 Definiciones

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

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

1#[test]
2fn align_baseline_child_padding() {
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(50f32),
10                height: taffy::style::Dimension::Length(50f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node10 = taffy
16        .new_leaf(taffy::style::Style {
17            size: taffy::geometry::Size {
18                width: taffy::style::Dimension::Length(50f32),
19                height: taffy::style::Dimension::Length(10f32),
20            },
21            ..Default::default()
22        })
23        .unwrap();
24    let node1 = taffy
25        .new_with_children(
26            taffy::style::Style {
27                flex_direction: taffy::style::FlexDirection::Column,
28                size: taffy::geometry::Size {
29                    width: taffy::style::Dimension::Length(50f32),
30                    height: taffy::style::Dimension::Length(20f32),
31                },
32                padding: taffy::geometry::Rect {
33                    left: taffy::style::LengthPercentage::Length(5f32),
34                    right: taffy::style::LengthPercentage::Length(5f32),
35                    top: taffy::style::LengthPercentage::Length(5f32),
36                    bottom: taffy::style::LengthPercentage::Length(5f32),
37                },
38                ..Default::default()
39            },
40            &[node10],
41        )
42        .unwrap();
43    let node = taffy
44        .new_with_children(
45            taffy::style::Style {
46                align_items: Some(taffy::style::AlignItems::Baseline),
47                size: taffy::geometry::Size {
48                    width: taffy::style::Dimension::Length(100f32),
49                    height: taffy::style::Dimension::Length(100f32),
50                },
51                padding: taffy::geometry::Rect {
52                    left: taffy::style::LengthPercentage::Length(5f32),
53                    right: taffy::style::LengthPercentage::Length(5f32),
54                    top: taffy::style::LengthPercentage::Length(5f32),
55                    bottom: taffy::style::LengthPercentage::Length(5f32),
56                },
57                ..Default::default()
58            },
59            &[node0, node1],
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
69    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, 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(node1).unwrap();
116    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
117    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
118    assert_eq!(location.x, 45f32, "x of node {:?}. Expected {}. Actual {}", node1, 45f32, location.x);
119    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
120    #[cfg(feature = "content_size")]
121    assert_eq!(
122        layout.scroll_width(),
123        5f32,
124        "scroll_width of node {:?}. Expected {}. Actual {}",
125        node1,
126        5f32,
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        node1,
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(node10).unwrap();
140    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
141    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
142    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node10, 5f32, location.x);
143    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node10, 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        node10,
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        node10,
159        0f32,
160        layout.scroll_height()
161    );
162}