gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definitions

⎇ 0.5.x tests/generated/flex/gap_column_gap_justify_space_evenly.rs Rust · 138 lines · 5.7 KB History Who touched what raw

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

1#[test]
2fn gap_column_gap_justify_space_evenly() {
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            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(20f32), height: auto() },
15            ..Default::default()
16        })
17        .unwrap();
18    let node2 = taffy
19        .new_leaf(taffy::style::Style {
20            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(20f32), height: auto() },
21            ..Default::default()
22        })
23        .unwrap();
24    let node = taffy
25        .new_with_children(
26            taffy::style::Style {
27                justify_content: Some(taffy::style::JustifyContent::SpaceEvenly),
28                gap: taffy::geometry::Size { width: taffy::style::LengthPercentage::Length(10f32), height: zero() },
29                size: taffy::geometry::Size {
30                    width: taffy::style::Dimension::Length(100f32),
31                    height: taffy::style::Dimension::Length(100f32),
32                },
33                ..Default::default()
34            },
35            &[node0, node1, node2],
36        )
37        .unwrap();
38    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
39    println!("\nComputed tree:");
40    taffy.print_tree(node);
41    println!();
42    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
43    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
44    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
45    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
46    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
47    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
48    #[cfg(feature = "content_size")]
49    assert_eq!(
50        layout.scroll_width(),
51        0f32,
52        "scroll_width of node {:?}. Expected {}. Actual {}",
53        node,
54        0f32,
55        layout.scroll_width()
56    );
57    #[cfg(feature = "content_size")]
58    assert_eq!(
59        layout.scroll_height(),
60        0f32,
61        "scroll_height of node {:?}. Expected {}. Actual {}",
62        node,
63        0f32,
64        layout.scroll_height()
65    );
66    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
67    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
68    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
69    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
70    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
71    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 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        node0,
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        node0,
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(node1).unwrap();
92    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
93    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
94    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
95    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
96    #[cfg(feature = "content_size")]
97    assert_eq!(
98        layout.scroll_width(),
99        0f32,
100        "scroll_width of node {:?}. Expected {}. Actual {}",
101        node1,
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        node1,
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(node2).unwrap();
116    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
117    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
118    assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node2, 75f32, location.x);
119    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
120    #[cfg(feature = "content_size")]
121    assert_eq!(
122        layout.scroll_width(),
123        0f32,
124        "scroll_width of node {:?}. Expected {}. Actual {}",
125        node2,
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        node2,
135        0f32,
136        layout.scroll_height()
137    );
138}