gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 238Markdown 7TOML 31441 Definiciones

⎇ 0.2.x tests/generated/flex_grow_less_than_factor_one.rs Rust · 51 líneas · 2.2 KB Historia Quién tocó qué crudo

Rename FlexboxLayout back to Style (#251) 49893a7d9 · Nico Burns ·

1#[test]
2fn flex_grow_less_than_factor_one() {
3    let mut taffy = taffy::Taffy::new();
4    let node0 = taffy
5        .new_with_children(
6            taffy::style::Style {
7                flex_grow: 0.2f32,
8                flex_shrink: 0f32,
9                flex_basis: taffy::style::Dimension::Points(40f32),
10                ..Default::default()
11            },
12            &[],
13        )
14        .unwrap();
15    let node1 = taffy
16        .new_with_children(taffy::style::Style { flex_grow: 0.2f32, flex_shrink: 0f32, ..Default::default() }, &[])
17        .unwrap();
18    let node2 = taffy
19        .new_with_children(taffy::style::Style { flex_grow: 0.4f32, flex_shrink: 0f32, ..Default::default() }, &[])
20        .unwrap();
21    let node = taffy
22        .new_with_children(
23            taffy::style::Style {
24                size: taffy::geometry::Size {
25                    width: taffy::style::Dimension::Points(500f32),
26                    height: taffy::style::Dimension::Points(200f32),
27                    ..Default::default()
28                },
29                ..Default::default()
30            },
31            &[node0, node1, node2],
32        )
33        .unwrap();
34    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
35    assert_eq!(taffy.layout(node).unwrap().size.width, 500f32);
36    assert_eq!(taffy.layout(node).unwrap().size.height, 200f32);
37    assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
38    assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
39    assert_eq!(taffy.layout(node0).unwrap().size.width, 132f32);
40    assert_eq!(taffy.layout(node0).unwrap().size.height, 200f32);
41    assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32);
42    assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32);
43    assert_eq!(taffy.layout(node1).unwrap().size.width, 92f32);
44    assert_eq!(taffy.layout(node1).unwrap().size.height, 200f32);
45    assert_eq!(taffy.layout(node1).unwrap().location.x, 132f32);
46    assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32);
47    assert_eq!(taffy.layout(node2).unwrap().size.width, 184f32);
48    assert_eq!(taffy.layout(node2).unwrap().size.height, 200f32);
49    assert_eq!(taffy.layout(node2).unwrap().location.x, 224f32);
50    assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32);
51}