tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Definitions

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/leaf_with_content_and_padding_border.rs Rust · 44 lines · 2.0 KB History Who touched what raw

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

1#[test]
2fn leaf_with_content_and_padding_border() {
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                padding: taffy::geometry::Rect {
10                    left: taffy::style::LengthPercentage::Length(8f32),
11                    right: taffy::style::LengthPercentage::Length(4f32),
12                    top: taffy::style::LengthPercentage::Length(2f32),
13                    bottom: taffy::style::LengthPercentage::Length(6f32),
14                },
15                border: taffy::geometry::Rect {
16                    left: taffy::style::LengthPercentage::Length(7f32),
17                    right: taffy::style::LengthPercentage::Length(3f32),
18                    top: taffy::style::LengthPercentage::Length(1f32),
19                    bottom: taffy::style::LengthPercentage::Length(5f32),
20                },
21                ..Default::default()
22            },
23            taffy::tree::MeasureFunc::Raw(|known_dimensions, available_space| {
24                const TEXT: &str = "HHHH";
25                super::measure_standard_text(
26                    known_dimensions,
27                    available_space,
28                    TEXT,
29                    super::WritingMode::Horizontal,
30                    None,
31                )
32            }),
33        )
34        .unwrap();
35    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
36    println!("\nComputed tree:");
37    taffy::util::print_tree(&taffy, node);
38    println!();
39    let Layout { size, location, .. } = taffy.layout(node).unwrap();
40    assert_eq!(size.width, 62f32, "width of node {:?}. Expected {}. Actual {}", node, 62f32, size.width);
41    assert_eq!(size.height, 24f32, "height of node {:?}. Expected {}. Actual {}", node, 24f32, size.height);
42    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
43    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
44}