gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ 0.5.x tests/generated/flex/gap_column_gap_mixed_flexible.rs Rust · 139 líneas · 5.6 KB Historia Quién tocó qué crudo

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

1#[test]
2fn gap_column_gap_mixed_flexible() {
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 { width: taffy::style::Dimension::Length(20f32), height: auto() },
9            ..Default::default()
10        })
11        .unwrap();
12    let node1 = taffy
13        .new_leaf(taffy::style::Style {
14            flex_grow: 1f32,
15            flex_shrink: 1f32,
16            flex_basis: taffy::style::Dimension::Percent(0f32),
17            ..Default::default()
18        })
19        .unwrap();
20    let node2 = taffy
21        .new_leaf(taffy::style::Style {
22            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(20f32), height: auto() },
23            ..Default::default()
24        })
25        .unwrap();
26    let node = taffy
27        .new_with_children(
28            taffy::style::Style {
29                gap: taffy::geometry::Size { width: taffy::style::LengthPercentage::Length(10f32), height: zero() },
30                size: taffy::geometry::Size {
31                    width: taffy::style::Dimension::Length(80f32),
32                    height: taffy::style::Dimension::Length(100f32),
33                },
34                ..Default::default()
35            },
36            &[node0, node1, node2],
37        )
38        .unwrap();
39    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
40    println!("\nComputed tree:");
41    taffy.print_tree(node);
42    println!();
43    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
44    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
45    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
46    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
48    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
49    #[cfg(feature = "content_size")]
50    assert_eq!(
51        layout.scroll_width(),
52        0f32,
53        "scroll_width of node {:?}. Expected {}. Actual {}",
54        node,
55        0f32,
56        layout.scroll_width()
57    );
58    #[cfg(feature = "content_size")]
59    assert_eq!(
60        layout.scroll_height(),
61        0f32,
62        "scroll_height of node {:?}. Expected {}. Actual {}",
63        node,
64        0f32,
65        layout.scroll_height()
66    );
67    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
68    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
69    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
70    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
73    #[cfg(feature = "content_size")]
74    assert_eq!(
75        layout.scroll_width(),
76        0f32,
77        "scroll_width of node {:?}. Expected {}. Actual {}",
78        node0,
79        0f32,
80        layout.scroll_width()
81    );
82    #[cfg(feature = "content_size")]
83    assert_eq!(
84        layout.scroll_height(),
85        0f32,
86        "scroll_height of node {:?}. Expected {}. Actual {}",
87        node0,
88        0f32,
89        layout.scroll_height()
90    );
91    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
92    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
93    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
94    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
95    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node1, 30f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
97    #[cfg(feature = "content_size")]
98    assert_eq!(
99        layout.scroll_width(),
100        0f32,
101        "scroll_width of node {:?}. Expected {}. Actual {}",
102        node1,
103        0f32,
104        layout.scroll_width()
105    );
106    #[cfg(feature = "content_size")]
107    assert_eq!(
108        layout.scroll_height(),
109        0f32,
110        "scroll_height of node {:?}. Expected {}. Actual {}",
111        node1,
112        0f32,
113        layout.scroll_height()
114    );
115    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
116    let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
117    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
118    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
119    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node2, 60f32, location.x);
120    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
121    #[cfg(feature = "content_size")]
122    assert_eq!(
123        layout.scroll_width(),
124        0f32,
125        "scroll_width of node {:?}. Expected {}. Actual {}",
126        node2,
127        0f32,
128        layout.scroll_width()
129    );
130    #[cfg(feature = "content_size")]
131    assert_eq!(
132        layout.scroll_height(),
133        0f32,
134        "scroll_height of node {:?}. Expected {}. Actual {}",
135        node2,
136        0f32,
137        layout.scroll_height()
138    );
139}