gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 254C 19JavaScript 81365 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/margin_auto_left_stretching_child.rs Rust · 61 siq'ikuna · 3.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn margin_auto_left_stretching_child() {
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            flex_grow: 1f32,
9            flex_shrink: 1f32,
10            flex_basis: taffy::style::Dimension::Percent(0f32),
11            margin: taffy::geometry::Rect {
12                left: taffy::style::LengthPercentageAuto::Auto,
13                right: zero(),
14                top: zero(),
15                bottom: zero(),
16            },
17            ..Default::default()
18        })
19        .unwrap();
20    let node1 = taffy
21        .new_leaf(taffy::style::Style {
22            size: taffy::geometry::Size {
23                width: taffy::style::Dimension::Length(50f32),
24                height: taffy::style::Dimension::Length(50f32),
25            },
26            ..Default::default()
27        })
28        .unwrap();
29    let node = taffy
30        .new_with_children(
31            taffy::style::Style {
32                align_items: Some(taffy::style::AlignItems::Center),
33                size: taffy::geometry::Size {
34                    width: taffy::style::Dimension::Length(200f32),
35                    height: taffy::style::Dimension::Length(200f32),
36                },
37                ..Default::default()
38            },
39            &[node0, node1],
40        )
41        .unwrap();
42    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
43    println!("\nComputed tree:");
44    taffy::util::print_tree(&taffy, node);
45    println!();
46    let Layout { size, location, .. } = taffy.layout(node).unwrap();
47    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
48    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
51    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
52    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node0, 150f32, size.width);
53    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
55    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0, 100f32, location.y);
56    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
57    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
58    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
59    assert_eq!(location.x, 150f32, "x of node {:?}. Expected {}. Actual {}", node1, 150f32, location.x);
60    assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node1, 75f32, location.y);
61}