tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definiciones

⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227 tests/generated/leaf/leaf_overflow_scrollbars_overridden_by_available_space.rs Rust · 161 líneas · 6.3 KB Historia Quién tocó qué crudo

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

1#[test]
2#[allow(non_snake_case)]
3fn leaf_overflow_scrollbars_overridden_by_available_space__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            overflow: taffy::geometry::Point { x: taffy::style::Overflow::Scroll, y: taffy::style::Overflow::Scroll },
10            scrollbar_width: 15f32,
11            flex_grow: 1f32,
12            ..Default::default()
13        })
14        .unwrap();
15    let node = taffy
16        .new_with_children(
17            taffy::style::Style {
18                size: taffy::geometry::Size {
19                    width: taffy::style::Dimension::Length(2f32),
20                    height: taffy::style::Dimension::Length(4f32),
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, 2f32, "width of node {:?}. Expected {}. Actual {}", node, 2f32, size.width);
34    assert_eq!(size.height, 4f32, "height of node {:?}. Expected {}. Actual {}", node, 4f32, 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, 2f32, "width of node {:?}. Expected {}. Actual {}", node0, 2f32, size.width);
58    assert_eq!(size.height, 4f32, "height of node {:?}. Expected {}. Actual {}", node0, 4f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, 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 leaf_overflow_scrollbars_overridden_by_available_space__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            overflow: taffy::geometry::Point { x: taffy::style::Overflow::Scroll, y: taffy::style::Overflow::Scroll },
91            scrollbar_width: 15f32,
92            flex_grow: 1f32,
93            ..Default::default()
94        })
95        .unwrap();
96    let node = taffy
97        .new_with_children(
98            taffy::style::Style {
99                box_sizing: taffy::style::BoxSizing::ContentBox,
100                size: taffy::geometry::Size {
101                    width: taffy::style::Dimension::Length(2f32),
102                    height: taffy::style::Dimension::Length(4f32),
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, 2f32, "width of node {:?}. Expected {}. Actual {}", node, 2f32, size.width);
116    assert_eq!(size.height, 4f32, "height of node {:?}. Expected {}. Actual {}", node, 4f32, 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, 2f32, "width of node {:?}. Expected {}. Actual {}", node0, 2f32, size.width);
140    assert_eq!(size.height, 4f32, "height of node {:?}. Expected {}. Actual {}", node0, 4f32, size.height);
141    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, 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}