gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/gridflex_kitchen_sink.rs Rust · 170 líneas · 10.6 KB Historia Quién tocó qué crudo

Grid: Rename Flex to Fraction (#350) 71027a8de · Nico Burns ·

1#[test]
2fn gridflex_kitchen_sink() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node000 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), height: auto() },
10            ..Default::default()
11        })
12        .unwrap();
13    let node00100 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), height: auto() },
16            ..Default::default()
17        })
18        .unwrap();
19    let node00101 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20    let node00102 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21    let node00103 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
22    let node0010 = taffy
23        .new_with_children(
24            taffy::style::Style {
25                display: taffy::style::Display::Grid,
26                grid_template_rows: vec![percent(0.3f32), percent(0.1f32)],
27                grid_template_columns: vec![auto(), percent(0.1f32)],
28                ..Default::default()
29            },
30            &[node00100, node00101, node00102, node00103],
31        )
32        .unwrap();
33    let node001 = taffy
34        .new_with_children(
35            taffy::style::Style {
36                flex_grow: 1f32,
37                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() },
38                ..Default::default()
39            },
40            &[node0010],
41        )
42        .unwrap();
43    let node00 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node000, node001]).unwrap();
44    let node01 = taffy
45        .new_leaf_with_measure(
46            taffy::style::Style { ..Default::default() },
47            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
48                const TEXT: &str = "HH";
49                super::measure_standard_text(
50                    known_dimensions,
51                    available_space,
52                    TEXT,
53                    super::WritingMode::Horizontal,
54                    None,
55                )
56            }),
57        )
58        .unwrap();
59    let node02 = taffy
60        .new_leaf_with_measure(
61            taffy::style::Style { ..Default::default() },
62            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
63                const TEXT: &str = "HH";
64                super::measure_standard_text(
65                    known_dimensions,
66                    available_space,
67                    TEXT,
68                    super::WritingMode::Horizontal,
69                    None,
70                )
71            }),
72        )
73        .unwrap();
74    let node03 = taffy
75        .new_leaf_with_measure(
76            taffy::style::Style { ..Default::default() },
77            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
78                const TEXT: &str = "HH";
79                super::measure_standard_text(
80                    known_dimensions,
81                    available_space,
82                    TEXT,
83                    super::WritingMode::Horizontal,
84                    None,
85                )
86            }),
87        )
88        .unwrap();
89    let node0 = taffy
90        .new_with_children(
91            taffy::style::Style {
92                display: taffy::style::Display::Grid,
93                grid_template_rows: vec![fr(1f32), fr(1f32)],
94                grid_template_columns: vec![fr(1f32), fr(1f32)],
95                ..Default::default()
96            },
97            &[node00, node01, node02, node03],
98        )
99        .unwrap();
100    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
101    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
102    println!("\nComputed tree:");
103    taffy::debug::print_tree(&taffy, node);
104    println!();
105    let Layout { size, location, .. } = taffy.layout(node).unwrap();
106    assert_eq!(size.width, 140f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 140f32, size.width);
107    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.height);
108    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
109    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
110    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
111    assert_eq!(size.width, 140f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 140f32, size.width);
112    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
113    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
114    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
115    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
116    assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 70f32, size.width);
117    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, size.height);
118    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
119    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
120    let Layout { size, location, .. } = taffy.layout(node000).unwrap();
121    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node000.data(), 20f32, size.width);
122    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000.data(), 10f32, size.height);
123    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.x);
124    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.y);
125    let Layout { size, location, .. } = taffy.layout(node001).unwrap();
126    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node001.data(), 50f32, size.width);
127    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node001.data(), 10f32, size.height);
128    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node001.data(), 20f32, location.x);
129    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node001.data(), 0f32, location.y);
130    let Layout { size, location, .. } = taffy.layout(node0010).unwrap();
131    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0010.data(), 20f32, size.width);
132    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0010.data(), 10f32, size.height);
133    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0010.data(), 0f32, location.x);
134    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0010.data(), 0f32, location.y);
135    let Layout { size, location, .. } = taffy.layout(node00100).unwrap();
136    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00100.data(), 20f32, size.width);
137    assert_eq!(size.height, 3f32, "height of node {:?}. Expected {}. Actual {}", node00100.data(), 3f32, size.height);
138    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00100.data(), 0f32, location.x);
139    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00100.data(), 0f32, location.y);
140    let Layout { size, location, .. } = taffy.layout(node00101).unwrap();
141    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00101.data(), 2f32, size.width);
142    assert_eq!(size.height, 3f32, "height of node {:?}. Expected {}. Actual {}", node00101.data(), 3f32, size.height);
143    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00101.data(), 20f32, location.x);
144    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00101.data(), 0f32, location.y);
145    let Layout { size, location, .. } = taffy.layout(node00102).unwrap();
146    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00102.data(), 20f32, size.width);
147    assert_eq!(size.height, 1f32, "height of node {:?}. Expected {}. Actual {}", node00102.data(), 1f32, size.height);
148    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00102.data(), 0f32, location.x);
149    assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node00102.data(), 3f32, location.y);
150    let Layout { size, location, .. } = taffy.layout(node00103).unwrap();
151    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node00103.data(), 2f32, size.width);
152    assert_eq!(size.height, 1f32, "height of node {:?}. Expected {}. Actual {}", node00103.data(), 1f32, size.height);
153    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00103.data(), 20f32, location.x);
154    assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node00103.data(), 3f32, location.y);
155    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
156    assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 70f32, size.width);
157    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 10f32, size.height);
158    assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 70f32, location.x);
159    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.y);
160    let Layout { size, location, .. } = taffy.layout(node02).unwrap();
161    assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node02.data(), 70f32, size.width);
162    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02.data(), 10f32, size.height);
163    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02.data(), 0f32, location.x);
164    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02.data(), 10f32, location.y);
165    let Layout { size, location, .. } = taffy.layout(node03).unwrap();
166    assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node03.data(), 70f32, size.width);
167    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03.data(), 10f32, size.height);
168    assert_eq!(location.x, 70f32, "x of node {:?}. Expected {}. Actual {}", node03.data(), 70f32, location.x);
169    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03.data(), 10f32, location.y);
170}