gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Sutichaykuna

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/overflow_scroll_main_axis_justify_content_end.rs Rust · 161 siq'ikuna · 6.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn overflow_scroll_main_axis_justify_content_end__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_shrink: 0f32,
10            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
11            ..Default::default()
12        })
13        .unwrap();
14    let node = taffy
15        .new_with_children(
16            taffy::style::Style {
17                justify_content: Some(taffy::style::JustifyContent::End),
18                size: taffy::geometry::Size {
19                    width: taffy::style::Dimension::Length(100f32),
20                    height: taffy::style::Dimension::Length(100f32),
21                },
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    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
32    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
33    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
34    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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    #[cfg(feature = "content_size")]
38    assert_eq!(
39        layout.scroll_width(),
40        0f32,
41        "scroll_width of node {:?}. Expected {}. Actual {}",
42        node,
43        0f32,
44        layout.scroll_width()
45    );
46    #[cfg(feature = "content_size")]
47    assert_eq!(
48        layout.scroll_height(),
49        0f32,
50        "scroll_height of node {:?}. Expected {}. Actual {}",
51        node,
52        0f32,
53        layout.scroll_height()
54    );
55    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
56    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
57    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
58    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
59    assert_eq!(location.x, -100f32, "x of node {:?}. Expected {}. Actual {}", node0, -100f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
61    #[cfg(feature = "content_size")]
62    assert_eq!(
63        layout.scroll_width(),
64        0f32,
65        "scroll_width of node {:?}. Expected {}. Actual {}",
66        node0,
67        0f32,
68        layout.scroll_width()
69    );
70    #[cfg(feature = "content_size")]
71    assert_eq!(
72        layout.scroll_height(),
73        0f32,
74        "scroll_height of node {:?}. Expected {}. Actual {}",
75        node0,
76        0f32,
77        layout.scroll_height()
78    );
79}
80
81#[test]
82#[allow(non_snake_case)]
83fn overflow_scroll_main_axis_justify_content_end__content_box() {
84    #[allow(unused_imports)]
85    use taffy::{prelude::*, tree::Layout, TaffyTree};
86    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
87    let node0 = taffy
88        .new_leaf(taffy::style::Style {
89            box_sizing: taffy::style::BoxSizing::ContentBox,
90            flex_shrink: 0f32,
91            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
92            ..Default::default()
93        })
94        .unwrap();
95    let node = taffy
96        .new_with_children(
97            taffy::style::Style {
98                box_sizing: taffy::style::BoxSizing::ContentBox,
99                justify_content: Some(taffy::style::JustifyContent::End),
100                size: taffy::geometry::Size {
101                    width: taffy::style::Dimension::Length(100f32),
102                    height: taffy::style::Dimension::Length(100f32),
103                },
104                ..Default::default()
105            },
106            &[node0],
107        )
108        .unwrap();
109    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
110    println!("\nComputed tree:");
111    taffy.print_tree(node);
112    println!();
113    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
114    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
115    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
116    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
117    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
118    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
119    #[cfg(feature = "content_size")]
120    assert_eq!(
121        layout.scroll_width(),
122        0f32,
123        "scroll_width of node {:?}. Expected {}. Actual {}",
124        node,
125        0f32,
126        layout.scroll_width()
127    );
128    #[cfg(feature = "content_size")]
129    assert_eq!(
130        layout.scroll_height(),
131        0f32,
132        "scroll_height of node {:?}. Expected {}. Actual {}",
133        node,
134        0f32,
135        layout.scroll_height()
136    );
137    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
138    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
139    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
140    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
141    assert_eq!(location.x, -100f32, "x of node {:?}. Expected {}. Actual {}", node0, -100f32, location.x);
142    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
143    #[cfg(feature = "content_size")]
144    assert_eq!(
145        layout.scroll_width(),
146        0f32,
147        "scroll_width of node {:?}. Expected {}. Actual {}",
148        node0,
149        0f32,
150        layout.scroll_width()
151    );
152    #[cfg(feature = "content_size")]
153    assert_eq!(
154        layout.scroll_height(),
155        0f32,
156        "scroll_height of node {:?}. Expected {}. Actual {}",
157        node0,
158        0f32,
159        layout.scroll_height()
160    );
161}