gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 254C 19JavaScript 81365 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_overflow_scrollbars_overriden_by_available_space.rs Rust · 64 siq'ikuna · 3.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement CSS Block layout (`Display::Block`) (#474) 544399619 · Nico Burns ·

1#[test]
2fn block_overflow_scrollbars_overriden_by_available_space() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            position: taffy::style::Position::Absolute,
9            inset: taffy::geometry::Rect {
10                left: taffy::style::LengthPercentageAuto::Length(0f32),
11                right: taffy::style::LengthPercentageAuto::Length(0f32),
12                top: taffy::style::LengthPercentageAuto::Length(0f32),
13                bottom: taffy::style::LengthPercentageAuto::Length(0f32),
14            },
15            ..Default::default()
16        })
17        .unwrap();
18    let node0 = taffy
19        .new_with_children(
20            taffy::style::Style {
21                display: taffy::style::Display::Block,
22                overflow: taffy::geometry::Point {
23                    x: taffy::style::Overflow::Scroll,
24                    y: taffy::style::Overflow::Scroll,
25                },
26                scrollbar_width: 15f32,
27                ..Default::default()
28            },
29            &[node00],
30        )
31        .unwrap();
32    let node = taffy
33        .new_with_children(
34            taffy::style::Style {
35                display: taffy::style::Display::Block,
36                size: taffy::geometry::Size {
37                    width: taffy::style::Dimension::Length(2f32),
38                    height: taffy::style::Dimension::Length(4f32),
39                },
40                ..Default::default()
41            },
42            &[node0],
43        )
44        .unwrap();
45    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
46    println!("\nComputed tree:");
47    taffy::util::print_tree(&taffy, node);
48    println!();
49    let Layout { size, location, .. } = taffy.layout(node).unwrap();
50    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node, 2f32, size.width);
51    assert_eq!(size.height, 4f32, "height of node {:?}. Expected {}. Actual {}", node, 4f32, size.height);
52    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
54    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
55    assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node0, 2f32, size.width);
56    assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node0, 15f32, size.height);
57    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
58    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
59    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
60    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node00, 0f32, size.width);
61    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00, 0f32, size.height);
62    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
63    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
64}