gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1108HTML 1039Markdown 12TOML 74481 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/flex_basis_smaller_than_main_dimen_column.rs Rust · 40 siq'ikuna · 2.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 flex_basis_smaller_than_main_dimen_column() {
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_basis: taffy::style::Dimension::Length(10f32),
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(50f32),
11                height: taffy::style::Dimension::Length(50f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node = taffy
17        .new_with_children(
18            taffy::style::Style {
19                flex_direction: taffy::style::FlexDirection::Column,
20                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
21                ..Default::default()
22            },
23            &[node0],
24        )
25        .unwrap();
26    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
27    println!("\nComputed tree:");
28    taffy::util::print_tree(&taffy, node);
29    println!();
30    let Layout { size, location, .. } = taffy.layout(node).unwrap();
31    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
32    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
33    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
34    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
35    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
36    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
37    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
38    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
39    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
40}