gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definiciones

⎇ 0.3.x tests/generated/aspect_ratio_flex_column_fill_max_height.rs Rust · 37 líneas · 2.5 KB Historia Quién tocó qué crudo

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

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