gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1068HTML 999Markdown 12TOML 83188 Definitions

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/aspect_ratio_flex_column_fill_max_height.rs Rust · 36 lines · 2.4 KB History Who touched what raw

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

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