gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 979HTML 924Markdown 12TOML 82994 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/align_baseline_child_margin_percent.rs Rust · 86 siq'ikuna · 4.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename `Points`/`points` to `Length`/`length` in many APIs (#459) 55abeaf2e · Simon Sapin ·

1#[test]
2fn align_baseline_child_margin_percent() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(50f32),
10                height: taffy::style::Dimension::Length(50f32),
11            },
12            margin: taffy::geometry::Rect {
13                left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14                right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
15                top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
16                bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
17            },
18            ..Default::default()
19        })
20        .unwrap();
21    let node10 = taffy
22        .new_leaf(taffy::style::Style {
23            size: taffy::geometry::Size {
24                width: taffy::style::Dimension::Length(50f32),
25                height: taffy::style::Dimension::Length(10f32),
26            },
27            margin: taffy::geometry::Rect {
28                left: taffy::style::LengthPercentageAuto::Percent(0.01f32),
29                right: taffy::style::LengthPercentageAuto::Percent(0.01f32),
30                top: taffy::style::LengthPercentageAuto::Percent(0.01f32),
31                bottom: taffy::style::LengthPercentageAuto::Percent(0.01f32),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node1 = taffy
37        .new_with_children(
38            taffy::style::Style {
39                flex_direction: taffy::style::FlexDirection::Column,
40                size: taffy::geometry::Size {
41                    width: taffy::style::Dimension::Length(50f32),
42                    height: taffy::style::Dimension::Length(20f32),
43                },
44                ..Default::default()
45            },
46            &[node10],
47        )
48        .unwrap();
49    let node = taffy
50        .new_with_children(
51            taffy::style::Style {
52                align_items: Some(taffy::style::AlignItems::Baseline),
53                size: taffy::geometry::Size {
54                    width: taffy::style::Dimension::Length(100f32),
55                    height: taffy::style::Dimension::Length(100f32),
56                },
57                ..Default::default()
58            },
59            &[node0, node1],
60        )
61        .unwrap();
62    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
63    println!("\nComputed tree:");
64    taffy::util::print_tree(&taffy, node);
65    println!();
66    let Layout { size, location, .. } = taffy.layout(node).unwrap();
67    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
68    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
71    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
72    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
73    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
74    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
75    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
76    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
77    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
78    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
79    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
80    assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node1, 45f32, location.y);
81    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
82    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
83    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
84    assert_eq!(location.x, 1f32, "x of node {:?}. Expected {}. Actual {}", node10, 1f32, location.x);
85    assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node10, 1f32, location.y);
86}