gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Definitions

⎇ 48e4800f14c6af5cd26275fb570d11b93e279654 tests/generated/flex/aspect_ratio_flex_row_fill_width_flex.rs Rust · 41 lines · 2.0 KB History Who touched what raw

Sort test fixtures and generated tests into folders (#514) 24b8faf43 · aemreaydin ·

1#[test]
2fn aspect_ratio_flex_row_fill_width_flex() {
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 { width: auto(), height: taffy::style::Dimension::Length(50f32) },
9            aspect_ratio: Some(2f32),
10            ..Default::default()
11        })
12        .unwrap();
13    let node = taffy
14        .new_with_children(
15            taffy::style::Style {
16                display: taffy::style::Display::Grid,
17                align_items: Some(taffy::style::AlignItems::Start),
18                size: taffy::geometry::Size {
19                    width: taffy::style::Dimension::Length(100f32),
20                    height: taffy::style::Dimension::Length(100f32),
21                },
22                ..Default::default()
23            },
24            &[node0],
25        )
26        .unwrap();
27    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
28    println!("\nComputed tree:");
29    taffy::util::print_tree(&taffy, node);
30    println!();
31    let Layout { size, location, .. } = taffy.layout(node).unwrap();
32    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
33    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
34    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
35    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
36    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
37    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
38    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
39    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
40    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
41}