gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1116HTML 1041Markdown 12TOML 94780 Sutichaykuna

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/align_items_center_justify_content_center.rs Rust · 161 siq'ikuna · 6.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn align_items_center_justify_content_center() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node000 = taffy
7        .new_leaf_with_context(
8            taffy::style::Style {
9                size: taffy::geometry::Size {
10                    width: taffy::style::Dimension::Length(10f32),
11                    height: taffy::style::Dimension::Length(10f32),
12                },
13                ..Default::default()
14            },
15            crate::TextMeasure { text_content: "", writing_mode: crate::WritingMode::Horizontal, _aspect_ratio: None },
16        )
17        .unwrap();
18    let node00 = taffy
19        .new_with_children(
20            taffy::style::Style {
21                flex_direction: taffy::style::FlexDirection::Column,
22                align_items: Some(taffy::style::AlignItems::Center),
23                justify_content: Some(taffy::style::JustifyContent::Center),
24                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(1f32) },
25                margin: taffy::geometry::Rect {
26                    left: taffy::style::LengthPercentageAuto::Length(10f32),
27                    right: taffy::style::LengthPercentageAuto::Length(10f32),
28                    top: zero(),
29                    bottom: zero(),
30                },
31                ..Default::default()
32            },
33            &[node000],
34        )
35        .unwrap();
36    let node0 = taffy
37        .new_with_children(
38            taffy::style::Style {
39                flex_direction: taffy::style::FlexDirection::Column,
40                align_items: Some(taffy::style::AlignItems::Center),
41                justify_content: Some(taffy::style::JustifyContent::Center),
42                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
43                ..Default::default()
44            },
45            &[node00],
46        )
47        .unwrap();
48    let node = taffy
49        .new_with_children(
50            taffy::style::Style {
51                flex_direction: taffy::style::FlexDirection::Column,
52                size: taffy::geometry::Size {
53                    width: taffy::style::Dimension::Length(500f32),
54                    height: taffy::style::Dimension::Length(500f32),
55                },
56                ..Default::default()
57            },
58            &[node0],
59        )
60        .unwrap();
61    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
62    println!("\nComputed tree:");
63    taffy.print_tree(node);
64    println!();
65    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
66    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
67    assert_eq!(size.width, 500f32, "width of node {:?}. Expected {}. Actual {}", node, 500f32, size.width);
68    assert_eq!(size.height, 500f32, "height of node {:?}. Expected {}. Actual {}", node, 500f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 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        node,
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        node,
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(node0).unwrap();
91    assert_eq!(size.width, 500f32, "width of node {:?}. Expected {}. Actual {}", node0, 500f32, size.width);
92    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
93    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
94    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
95    #[cfg(feature = "content_size")]
96    assert_eq!(
97        layout.scroll_width(),
98        0f32,
99        "scroll_width of node {:?}. Expected {}. Actual {}",
100        node0,
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        node0,
110        0f32,
111        layout.scroll_height()
112    );
113    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
114    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
115    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node00, 10f32, size.width);
116    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
117    assert_eq!(location.x, 245f32, "x of node {:?}. Expected {}. Actual {}", node00, 245f32, location.x);
118    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
119    #[cfg(feature = "content_size")]
120    assert_eq!(
121        layout.scroll_width(),
122        0f32,
123        "scroll_width of node {:?}. Expected {}. Actual {}",
124        node00,
125        0f32,
126        layout.scroll_width()
127    );
128    #[cfg(feature = "content_size")]
129    assert_eq!(
130        layout.scroll_height(),
131        0f32,
132        "scroll_height of node {:?}. Expected {}. Actual {}",
133        node00,
134        0f32,
135        layout.scroll_height()
136    );
137    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
138    let layout @ Layout { size, location, .. } = taffy.layout(node000).unwrap();
139    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node000, 10f32, size.width);
140    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
141    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
142    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node000, 20f32, location.y);
143    #[cfg(feature = "content_size")]
144    assert_eq!(
145        layout.scroll_width(),
146        0f32,
147        "scroll_width of node {:?}. Expected {}. Actual {}",
148        node000,
149        0f32,
150        layout.scroll_width()
151    );
152    #[cfg(feature = "content_size")]
153    assert_eq!(
154        layout.scroll_height(),
155        0f32,
156        "scroll_height of node {:?}. Expected {}. Actual {}",
157        node000,
158        0f32,
159        layout.scroll_height()
160    );
161}