gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 496HTML 245JavaScript 8CSS 61214 Definiciones

⎇ 0.5.x tests/generated/flex/flex_shrink_to_zero.rs Rust · 145 líneas · 5.7 KB Historia Quién tocó qué crudo

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

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