tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94541 Sutichaykuna

⎇ float-layout tests/generated/flex/justify_content_row_min_width_and_margin.rs Rust · 89 siq'ikuna · 4.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn justify_content_row_min_width_and_margin__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(20f32),
11                height: taffy::style::Dimension::from_length(20f32),
12            },
13            margin: taffy::geometry::Rect { left: length(10f32), right: zero(), top: zero(), bottom: zero() },
14            ..Default::default()
15        })
16        .unwrap();
17    let node = taffy
18        .new_with_children(
19            taffy::style::Style {
20                justify_content: Some(taffy::style::JustifyContent::Center),
21                min_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
22                ..Default::default()
23            },
24            &[node0],
25        )
26        .unwrap();
27    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
28    println!("\nComputed tree:");
29    taffy.print_tree(node);
30    println!();
31    let layout = taffy.layout(node).unwrap();
32    let Layout { size, location, .. } = layout;
33    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
34    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
35    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
36    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
37    let layout = taffy.layout(node0).unwrap();
38    let Layout { size, location, .. } = layout;
39    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
40    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
41    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0, 20f32, location.x);
42    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
43}
44
45#[test]
46#[allow(non_snake_case)]
47fn justify_content_row_min_width_and_margin__content_box() {
48    #[allow(unused_imports)]
49    use taffy::{prelude::*, Layout};
50    let mut taffy = crate::new_test_tree();
51    let node0 = taffy
52        .new_leaf(taffy::style::Style {
53            box_sizing: taffy::style::BoxSizing::ContentBox,
54            size: taffy::geometry::Size {
55                width: taffy::style::Dimension::from_length(20f32),
56                height: taffy::style::Dimension::from_length(20f32),
57            },
58            margin: taffy::geometry::Rect { left: length(10f32), right: zero(), top: zero(), bottom: zero() },
59            ..Default::default()
60        })
61        .unwrap();
62    let node = taffy
63        .new_with_children(
64            taffy::style::Style {
65                box_sizing: taffy::style::BoxSizing::ContentBox,
66                justify_content: Some(taffy::style::JustifyContent::Center),
67                min_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
68                ..Default::default()
69            },
70            &[node0],
71        )
72        .unwrap();
73    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
74    println!("\nComputed tree:");
75    taffy.print_tree(node);
76    println!();
77    let layout = taffy.layout(node).unwrap();
78    let Layout { size, location, .. } = layout;
79    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
80    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
81    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
82    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
83    let layout = taffy.layout(node0).unwrap();
84    let Layout { size, location, .. } = layout;
85    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
86    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
87    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0, 20f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
89}