gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 230Rust 8TOML 3CSS 1315 Sutichaykuna

⎇ 48e4800f14c6af5cd26275fb570d11b93e279654 tests/generated/flex/gap_column_gap_determines_parent_width.rs Rust · 59 siq'ikuna · 3.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn gap_column_gap_determines_parent_width() {
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: taffy::style::Dimension::Length(10f32), height: auto() },
9            ..Default::default()
10        })
11        .unwrap();
12    let node1 = taffy
13        .new_leaf(taffy::style::Style {
14            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(20f32), height: auto() },
15            ..Default::default()
16        })
17        .unwrap();
18    let node2 = taffy
19        .new_leaf(taffy::style::Style {
20            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() },
21            ..Default::default()
22        })
23        .unwrap();
24    let node = taffy
25        .new_with_children(
26            taffy::style::Style {
27                align_items: Some(taffy::style::AlignItems::Stretch),
28                gap: taffy::geometry::Size { width: taffy::style::LengthPercentage::Length(10f32), height: zero() },
29                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
30                ..Default::default()
31            },
32            &[node0, node1, node2],
33        )
34        .unwrap();
35    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
36    println!("\nComputed tree:");
37    taffy::util::print_tree(&taffy, node);
38    println!();
39    let Layout { size, location, .. } = taffy.layout(node).unwrap();
40    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
41    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
42    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
43    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
44    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
45    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
46    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
48    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
49    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
50    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
51    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
52    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node1, 20f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
54    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
55    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node2, 30f32, size.width);
56    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
57    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
58    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
59}