tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/leaf_overflow_scrollbars_take_up_space_x_axis.rs Rust · 37 siq'ikuna · 1.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

Reserve space for padding/borders/scrollbars in lead nodes with measure functions (#497) 568f64332 · Nico Burns ·

1#[test]
2fn leaf_overflow_scrollbars_take_up_space_x_axis() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node = taffy
7        .new_leaf_with_measure(
8            taffy::style::Style {
9                overflow: taffy::geometry::Point {
10                    x: taffy::style::Overflow::Scroll,
11                    y: taffy::style::Overflow::Visible,
12                },
13                scrollbar_width: 15f32,
14                ..Default::default()
15            },
16            taffy::tree::MeasureFunc::Raw(|known_dimensions, available_space| {
17                const TEXT: &str = "HH";
18                super::measure_standard_text(
19                    known_dimensions,
20                    available_space,
21                    TEXT,
22                    super::WritingMode::Horizontal,
23                    None,
24                )
25            }),
26        )
27        .unwrap();
28    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
29    println!("\nComputed tree:");
30    taffy::util::print_tree(&taffy, node);
31    println!();
32    let Layout { size, location, .. } = taffy.layout(node).unwrap();
33    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
34    assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node, 25f32, 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}