tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

⎇ b952c2b38dc58e87f43dc263e17beb4174bc68e2 tests/generated/align_baseline_nested_child.rs Rust · 75 lines · 3.0 KB History Who touched what raw

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

1#[test]
2fn align_baseline_nested_child() {
3    let mut taffy = taffy::Taffy::new();
4    let node0 = taffy
5        .new_with_children(
6            taffy::style::Style {
7                size: taffy::geometry::Size {
8                    width: taffy::style::Dimension::Points(50f32),
9                    height: taffy::style::Dimension::Points(50f32),
10                    ..Default::default()
11                },
12                ..Default::default()
13            },
14            &[],
15        )
16        .unwrap();
17    let node10 = taffy
18        .new_with_children(
19            taffy::style::Style {
20                size: taffy::geometry::Size {
21                    width: taffy::style::Dimension::Points(50f32),
22                    height: taffy::style::Dimension::Points(10f32),
23                    ..Default::default()
24                },
25                ..Default::default()
26            },
27            &[],
28        )
29        .unwrap();
30    let node1 = taffy
31        .new_with_children(
32            taffy::style::Style {
33                flex_direction: taffy::style::FlexDirection::Column,
34                size: taffy::geometry::Size {
35                    width: taffy::style::Dimension::Points(50f32),
36                    height: taffy::style::Dimension::Points(20f32),
37                    ..Default::default()
38                },
39                ..Default::default()
40            },
41            &[node10],
42        )
43        .unwrap();
44    let node = taffy
45        .new_with_children(
46            taffy::style::Style {
47                align_items: taffy::style::AlignItems::Baseline,
48                size: taffy::geometry::Size {
49                    width: taffy::style::Dimension::Points(100f32),
50                    height: taffy::style::Dimension::Points(100f32),
51                    ..Default::default()
52                },
53                ..Default::default()
54            },
55            &[node0, node1],
56        )
57        .unwrap();
58    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
59    assert_eq!(taffy.layout(node).unwrap().size.width, 100f32);
60    assert_eq!(taffy.layout(node).unwrap().size.height, 100f32);
61    assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
62    assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
63    assert_eq!(taffy.layout(node0).unwrap().size.width, 50f32);
64    assert_eq!(taffy.layout(node0).unwrap().size.height, 50f32);
65    assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32);
66    assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32);
67    assert_eq!(taffy.layout(node1).unwrap().size.width, 50f32);
68    assert_eq!(taffy.layout(node1).unwrap().size.height, 20f32);
69    assert_eq!(taffy.layout(node1).unwrap().location.x, 50f32);
70    assert_eq!(taffy.layout(node1).unwrap().location.y, 40f32);
71    assert_eq!(taffy.layout(node10).unwrap().size.width, 50f32);
72    assert_eq!(taffy.layout(node10).unwrap().size.height, 10f32);
73    assert_eq!(taffy.layout(node10).unwrap().location.x, 0f32);
74    assert_eq!(taffy.layout(node10).unwrap().location.y, 0f32);
75}