gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definiciones

⎇ 48e4800f14c6af5cd26275fb570d11b93e279654 tests/generated/flex/justify_content_column_space_between_negative_space.rs Rust · 98 líneas · 5.2 KB Historia Quién tocó qué crudo

Fix `justify-content` and `align-content` when free space is negative (content overflows container) (#551) 48e4800f1 · Nico Burns ·

1#[test]
2fn justify_content_column_space_between_negative_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            flex_shrink: 0f32,
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Percent(0.8f32),
11                height: taffy::style::Dimension::Length(20f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node01 = taffy
17        .new_leaf(taffy::style::Style {
18            flex_shrink: 0f32,
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::Percent(0.8f32),
21                height: taffy::style::Dimension::Length(20f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node02 = taffy
27        .new_leaf(taffy::style::Style {
28            flex_shrink: 0f32,
29            size: taffy::geometry::Size {
30                width: taffy::style::Dimension::Percent(0.8f32),
31                height: taffy::style::Dimension::Length(20f32),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node0 = taffy
37        .new_with_children(
38            taffy::style::Style {
39                display: taffy::style::Display::Flex,
40                flex_direction: taffy::style::FlexDirection::Column,
41                align_items: Some(taffy::style::AlignItems::Center),
42                justify_content: Some(taffy::style::JustifyContent::SpaceBetween),
43                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
44                ..Default::default()
45            },
46            &[node00, node01, node02],
47        )
48        .unwrap();
49    let node = taffy
50        .new_with_children(
51            taffy::style::Style {
52                display: taffy::style::Display::Flex,
53                flex_direction: taffy::style::FlexDirection::Column,
54                size: taffy::geometry::Size {
55                    width: taffy::style::Dimension::Length(320f32),
56                    height: taffy::style::Dimension::Length(320f32),
57                },
58                border: taffy::geometry::Rect {
59                    left: taffy::style::LengthPercentage::Length(60f32),
60                    right: taffy::style::LengthPercentage::Length(60f32),
61                    top: taffy::style::LengthPercentage::Length(60f32),
62                    bottom: taffy::style::LengthPercentage::Length(60f32),
63                },
64                ..Default::default()
65            },
66            &[node0],
67        )
68        .unwrap();
69    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
70    println!("\nComputed tree:");
71    taffy::util::print_tree(&taffy, node);
72    println!();
73    let Layout { size, location, .. } = taffy.layout(node).unwrap();
74    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
75    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node, 320f32, size.height);
76    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
77    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
78    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
79    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
80    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
81    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node0, 60f32, location.x);
82    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node0, 60f32, location.y);
83    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
84    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
85    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
86    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
87    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
88    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
89    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node01, 160f32, size.width);
90    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
91    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
92    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node01, 20f32, location.y);
93    let Layout { size, location, .. } = taffy.layout(node02).unwrap();
94    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node02, 160f32, size.width);
95    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02, 20f32, size.height);
96    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node02, 20f32, location.x);
97    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node02, 40f32, location.y);
98}