gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ 0.5.x tests/generated/flex/absolute_child_with_cross_margin.rs Rust · 165 lines · 6.7 KB History Who touched what raw

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

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