gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 254C 19JavaScript 81377 Sutichaykuna

⎇ 48e4800f14c6af5cd26275fb570d11b93e279654 tests/generated/flex/justify_content_column_start_negative_space_gap.rs Rust · 102 siq'ikuna · 5.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn justify_content_column_start_negative_space_gap() {
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::Start),
43                gap: taffy::geometry::Size {
44                    width: taffy::style::LengthPercentage::Length(10f32),
45                    height: taffy::style::LengthPercentage::Length(10f32),
46                },
47                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
48                ..Default::default()
49            },
50            &[node00, node01, node02],
51        )
52        .unwrap();
53    let node = taffy
54        .new_with_children(
55            taffy::style::Style {
56                display: taffy::style::Display::Flex,
57                flex_direction: taffy::style::FlexDirection::Column,
58                size: taffy::geometry::Size {
59                    width: taffy::style::Dimension::Length(320f32),
60                    height: taffy::style::Dimension::Length(320f32),
61                },
62                border: taffy::geometry::Rect {
63                    left: taffy::style::LengthPercentage::Length(60f32),
64                    right: taffy::style::LengthPercentage::Length(60f32),
65                    top: taffy::style::LengthPercentage::Length(60f32),
66                    bottom: taffy::style::LengthPercentage::Length(60f32),
67                },
68                ..Default::default()
69            },
70            &[node0],
71        )
72        .unwrap();
73    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
74    println!("\nComputed tree:");
75    taffy::util::print_tree(&taffy, node);
76    println!();
77    let Layout { size, location, .. } = taffy.layout(node).unwrap();
78    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
79    assert_eq!(size.height, 320f32, "height of node {:?}. Expected {}. Actual {}", node, 320f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
82    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
83    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
84    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
85    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node0, 60f32, location.x);
86    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node0, 60f32, location.y);
87    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
88    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
89    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
90    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
91    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
92    let Layout { size, location, .. } = taffy.layout(node01).unwrap();
93    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node01, 160f32, size.width);
94    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
95    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01, 20f32, location.x);
96    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node01, 30f32, location.y);
97    let Layout { size, location, .. } = taffy.layout(node02).unwrap();
98    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node02, 160f32, size.width);
99    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node02, 20f32, size.height);
100    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node02, 20f32, location.x);
101    assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node02, 60f32, location.y);
102}