gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Sutichaykuna

⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32 tests/generated/absolute_aspect_ratio_fill_max_width.rs Rust · 35 siq'ikuna · 2.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

Fixes for aspect ratio and min/max sizes (#317) 610c92f31 · Nico Burns ·

1#[test]
2fn absolute_aspect_ratio_fill_max_width() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { position : taffy :: style :: Position :: Absolute , max_size : taffy :: geometry :: Size { width : auto () , height : taffy :: style :: Dimension :: Points (50f32) , } , aspect_ratio : Some (0.5f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (0.5f32)) }) ,) . unwrap () ;
8    let node = taffy
9        .new_with_children(
10            taffy::style::Style {
11                display: taffy::style::Display::Flex,
12                size: taffy::geometry::Size {
13                    width: taffy::style::Dimension::Points(400f32),
14                    height: taffy::style::Dimension::Points(300f32),
15                },
16                ..Default::default()
17            },
18            &[node0],
19        )
20        .unwrap();
21    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
22    println!("\nComputed tree:");
23    taffy::debug::print_tree(&taffy, node);
24    println!();
25    let Layout { size, location, .. } = taffy.layout(node).unwrap();
26    assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width);
27    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height);
28    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
29    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
30    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
31    assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 25f32, size.width);
32    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
33    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
34    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
35}