gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1116HTML 1041Markdown 12TOML 94780 Definiciones

⎇ 0.2.x tests/generated/flex_shrink_flex_grow_row.rs Rust · 60 líneas · 2.3 KB Historia Quién tocó qué crudo

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

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