tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definitions

⎇ 39cd0fcbbda7cd38cc6316e7339b1f3aed29e99f tests/generated/flex_grow_within_max_width.rs Rust · 53 lines · 2.1 KB History Who touched what raw

Rename `new_node` to `new_with_children` (#142) 5d00d8fb9 · Andreas Weibye ·

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