tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Definiciones

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/leaf_with_content_and_padding.rs Rust · 38 líneas · 1.7 KB Historia Quién tocó qué crudo

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

1#[test]
2fn leaf_with_content_and_padding() {
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                ..Default::default()
16            },
17            taffy::tree::MeasureFunc::Raw(|known_dimensions, available_space| {
18                const TEXT: &str = "HHHH";
19                super::measure_standard_text(
20                    known_dimensions,
21                    available_space,
22                    TEXT,
23                    super::WritingMode::Horizontal,
24                    None,
25                )
26            }),
27        )
28        .unwrap();
29    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
30    println!("\nComputed tree:");
31    taffy::util::print_tree(&taffy, node);
32    println!();
33    let Layout { size, location, .. } = taffy.layout(node).unwrap();
34    assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node, 52f32, size.width);
35    assert_eq!(size.height, 18f32, "height of node {:?}. Expected {}. Actual {}", node, 18f32, size.height);
36    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
37    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
38}