tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Sutichaykuna

⎇ 837d03fde9d8a4efa0f4eaf1e8be2fd34a719a50 tests/generated/justify_content_column_center_negative_space_gap.rs Rust · 103 siq'ikuna · 5.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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