tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91841 Definitions

⎇ direction-floats tests/generated/flex/justify_content_row_max_width_and_margin.rs Rust · 91 lines · 4.7 KB History Who touched what raw

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

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