tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definiciones

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/flex_grow_less_than_factor_one.rs Rust · 133 líneas · 7.0 KB Historia Quién tocó qué crudo

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn flex_grow_less_than_factor_one__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_grow: 0.2f32,
10            flex_shrink: 0f32,
11            flex_basis: taffy::style::Dimension::from_length(40f32),
12            ..Default::default()
13        })
14        .unwrap();
15    let node1 =
16        taffy.new_leaf(taffy::style::Style { flex_grow: 0.2f32, flex_shrink: 0f32, ..Default::default() }).unwrap();
17    let node2 =
18        taffy.new_leaf(taffy::style::Style { flex_grow: 0.4f32, flex_shrink: 0f32, ..Default::default() }).unwrap();
19    let node = taffy
20        .new_with_children(
21            taffy::style::Style {
22                size: taffy::geometry::Size {
23                    width: taffy::style::Dimension::from_length(500f32),
24                    height: taffy::style::Dimension::from_length(200f32),
25                },
26                ..Default::default()
27            },
28            &[node0, node1, node2],
29        )
30        .unwrap();
31    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
32    println!("\nComputed tree:");
33    taffy.print_tree(node);
34    println!();
35    let layout = taffy.layout(node).unwrap();
36    let Layout { size, location, .. } = layout;
37    assert_eq!(size.width, 500f32, "width of node {:?}. Expected {}. Actual {}", node, 500f32, size.width);
38    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
39    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
40    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
41    let layout = taffy.layout(node0).unwrap();
42    let Layout { size, location, .. } = layout;
43    assert_eq!(size.width, 132f32, "width of node {:?}. Expected {}. Actual {}", node0, 132f32, size.width);
44    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node0, 200f32, size.height);
45    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
46    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
47    let layout = taffy.layout(node1).unwrap();
48    let Layout { size, location, .. } = layout;
49    assert_eq!(size.width, 92f32, "width of node {:?}. Expected {}. Actual {}", node1, 92f32, size.width);
50    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node1, 200f32, size.height);
51    assert_eq!(location.x, 132f32, "x of node {:?}. Expected {}. Actual {}", node1, 132f32, location.x);
52    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
53    let layout = taffy.layout(node2).unwrap();
54    let Layout { size, location, .. } = layout;
55    assert_eq!(size.width, 184f32, "width of node {:?}. Expected {}. Actual {}", node2, 184f32, size.width);
56    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node2, 200f32, size.height);
57    assert_eq!(location.x, 224f32, "x of node {:?}. Expected {}. Actual {}", node2, 224f32, location.x);
58    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
59}
60
61#[test]
62#[allow(non_snake_case)]
63fn flex_grow_less_than_factor_one__content_box() {
64    #[allow(unused_imports)]
65    use taffy::{prelude::*, Layout};
66    let mut taffy = crate::new_test_tree();
67    let node0 = taffy
68        .new_leaf(taffy::style::Style {
69            box_sizing: taffy::style::BoxSizing::ContentBox,
70            flex_grow: 0.2f32,
71            flex_shrink: 0f32,
72            flex_basis: taffy::style::Dimension::from_length(40f32),
73            ..Default::default()
74        })
75        .unwrap();
76    let node1 = taffy
77        .new_leaf(taffy::style::Style {
78            box_sizing: taffy::style::BoxSizing::ContentBox,
79            flex_grow: 0.2f32,
80            flex_shrink: 0f32,
81            ..Default::default()
82        })
83        .unwrap();
84    let node2 = taffy
85        .new_leaf(taffy::style::Style {
86            box_sizing: taffy::style::BoxSizing::ContentBox,
87            flex_grow: 0.4f32,
88            flex_shrink: 0f32,
89            ..Default::default()
90        })
91        .unwrap();
92    let node = taffy
93        .new_with_children(
94            taffy::style::Style {
95                box_sizing: taffy::style::BoxSizing::ContentBox,
96                size: taffy::geometry::Size {
97                    width: taffy::style::Dimension::from_length(500f32),
98                    height: taffy::style::Dimension::from_length(200f32),
99                },
100                ..Default::default()
101            },
102            &[node0, node1, node2],
103        )
104        .unwrap();
105    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
106    println!("\nComputed tree:");
107    taffy.print_tree(node);
108    println!();
109    let layout = taffy.layout(node).unwrap();
110    let Layout { size, location, .. } = layout;
111    assert_eq!(size.width, 500f32, "width of node {:?}. Expected {}. Actual {}", node, 500f32, size.width);
112    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
113    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
114    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
115    let layout = taffy.layout(node0).unwrap();
116    let Layout { size, location, .. } = layout;
117    assert_eq!(size.width, 132f32, "width of node {:?}. Expected {}. Actual {}", node0, 132f32, size.width);
118    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node0, 200f32, size.height);
119    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
120    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
121    let layout = taffy.layout(node1).unwrap();
122    let Layout { size, location, .. } = layout;
123    assert_eq!(size.width, 92f32, "width of node {:?}. Expected {}. Actual {}", node1, 92f32, size.width);
124    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node1, 200f32, size.height);
125    assert_eq!(location.x, 132f32, "x of node {:?}. Expected {}. Actual {}", node1, 132f32, location.x);
126    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
127    let layout = taffy.layout(node2).unwrap();
128    let Layout { size, location, .. } = layout;
129    assert_eq!(size.width, 184f32, "width of node {:?}. Expected {}. Actual {}", node2, 184f32, size.width);
130    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node2, 200f32, size.height);
131    assert_eq!(location.x, 224f32, "x of node {:?}. Expected {}. Actual {}", node2, 224f32, location.x);
132    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
133}