tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 735HTML 687Markdown 12TOML 62433 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/grid/grid_max_width_smaller_than_min_content.rs Rust · 139 siq'ikuna · 7.4 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 grid_max_width_smaller_than_min_content__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node00 = taffy
8        .new_leaf_with_context(
9            taffy::style::Style { ..Default::default() },
10            crate::TestNodeContext::ahem_text("HHHH\u{200b}HHHH", crate::WritingMode::Horizontal),
11        )
12        .unwrap();
13    let node01 = taffy
14        .new_leaf_with_context(
15            taffy::style::Style { ..Default::default() },
16            crate::TestNodeContext::ahem_text("HHHH\u{200b}HHHH", crate::WritingMode::Horizontal),
17        )
18        .unwrap();
19    let node0 = taffy
20        .new_with_children(
21            taffy::style::Style {
22                display: taffy::style::Display::Grid,
23                grid_template_columns: vec![auto(), auto()],
24                max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
25                ..Default::default()
26            },
27            &[node00, node01],
28        )
29        .unwrap();
30    let node = taffy
31        .new_with_children(
32            taffy::style::Style {
33                display: taffy::style::Display::Grid,
34                grid_template_columns: vec![max_content()],
35                ..Default::default()
36            },
37            &[node0],
38        )
39        .unwrap();
40    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
41    println!("\nComputed tree:");
42    taffy.print_tree(node);
43    println!();
44    let layout = taffy.layout(node).unwrap();
45    let Layout { size, location, .. } = layout;
46    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
47    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
48    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
49    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
50    let layout = taffy.layout(node0).unwrap();
51    let Layout { size, location, .. } = layout;
52    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
53    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
55    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
56    let layout = taffy.layout(node00).unwrap();
57    let Layout { size, location, .. } = layout;
58    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
59    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
60    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
61    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
62    let layout = taffy.layout(node01).unwrap();
63    let Layout { size, location, .. } = layout;
64    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node01, 40f32, size.width);
65    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
66    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node01, 40f32, location.x);
67    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
68}
69
70#[test]
71#[allow(non_snake_case)]
72fn grid_max_width_smaller_than_min_content__content_box() {
73    #[allow(unused_imports)]
74    use taffy::{prelude::*, Layout};
75    let mut taffy = crate::new_test_tree();
76    let node00 = taffy
77        .new_leaf_with_context(
78            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
79            crate::TestNodeContext::ahem_text("HHHH\u{200b}HHHH", crate::WritingMode::Horizontal),
80        )
81        .unwrap();
82    let node01 = taffy
83        .new_leaf_with_context(
84            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
85            crate::TestNodeContext::ahem_text("HHHH\u{200b}HHHH", crate::WritingMode::Horizontal),
86        )
87        .unwrap();
88    let node0 = taffy
89        .new_with_children(
90            taffy::style::Style {
91                display: taffy::style::Display::Grid,
92                box_sizing: taffy::style::BoxSizing::ContentBox,
93                grid_template_columns: vec![auto(), auto()],
94                max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
95                ..Default::default()
96            },
97            &[node00, node01],
98        )
99        .unwrap();
100    let node = taffy
101        .new_with_children(
102            taffy::style::Style {
103                display: taffy::style::Display::Grid,
104                box_sizing: taffy::style::BoxSizing::ContentBox,
105                grid_template_columns: vec![max_content()],
106                ..Default::default()
107            },
108            &[node0],
109        )
110        .unwrap();
111    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
112    println!("\nComputed tree:");
113    taffy.print_tree(node);
114    println!();
115    let layout = taffy.layout(node).unwrap();
116    let Layout { size, location, .. } = layout;
117    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
118    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
119    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
120    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
121    let layout = taffy.layout(node0).unwrap();
122    let Layout { size, location, .. } = layout;
123    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
124    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
125    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
126    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
127    let layout = taffy.layout(node00).unwrap();
128    let Layout { size, location, .. } = layout;
129    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
130    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
131    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
132    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
133    let layout = taffy.layout(node01).unwrap();
134    let Layout { size, location, .. } = layout;
135    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node01, 40f32, size.width);
136    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
137    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node01, 40f32, location.x);
138    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
139}