gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 0.5.x tests/generated/blockflex/blockflex_flex_in_block.rs Rust · 141 líneas · 5.6 KB Historia Quién tocó qué crudo

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

1#[test]
2fn blockflex_flex_in_block() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(50f32),
10                height: taffy::style::Dimension::Length(50f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node0 = taffy
16        .new_with_children(
17            taffy::style::Style { display: taffy::style::Display::Flex, ..Default::default() },
18            &[node00],
19        )
20        .unwrap();
21    let node1 = taffy
22        .new_leaf(taffy::style::Style {
23            display: taffy::style::Display::Block,
24            size: taffy::geometry::Size {
25                width: taffy::style::Dimension::Length(50f32),
26                height: taffy::style::Dimension::Length(20f32),
27            },
28            ..Default::default()
29        })
30        .unwrap();
31    let node = taffy
32        .new_with_children(
33            taffy::style::Style {
34                display: taffy::style::Display::Block,
35                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
36                ..Default::default()
37            },
38            &[node0, node1],
39        )
40        .unwrap();
41    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
42    println!("\nComputed tree:");
43    taffy.print_tree(node);
44    println!();
45    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
46    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
47    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
48    assert_eq!(size.height, 70f32, "height of node {:?}. Expected {}. Actual {}", node, 70f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
51    #[cfg(feature = "content_size")]
52    assert_eq!(
53        layout.scroll_width(),
54        0f32,
55        "scroll_width of node {:?}. Expected {}. Actual {}",
56        node,
57        0f32,
58        layout.scroll_width()
59    );
60    #[cfg(feature = "content_size")]
61    assert_eq!(
62        layout.scroll_height(),
63        0f32,
64        "scroll_height of node {:?}. Expected {}. Actual {}",
65        node,
66        0f32,
67        layout.scroll_height()
68    );
69    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
70    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
71    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
72    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
73    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
74    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 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        node0,
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        node0,
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(node00).unwrap();
95    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
96    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
97    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
98    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 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        node00,
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        node00,
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, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
120    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
121    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
122    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, 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}