tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94541 Definitions

⎇ 0596475afda99229de96976e73b2d637c78fdb8b benches/generated/grid_fit_content_percent_definite_min_content.rs Rust · 33 lines · 1.2 KB History Who touched what raw

Fix grid track sizing for `fit-content(percentage)` and for items spanning percentage gaps (#335) 0596475af · Nico Burns ·

1pub fn compute() {
2    #[allow(unused_imports)]
3    use taffy::prelude::*;
4    let mut taffy = taffy::Taffy::new();
5    let node0 = taffy
6        .new_leaf_with_measure(
7            taffy::style::Style { ..Default::default() },
8            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
9                const TEXT: &str = "HHHH\u{200b}HH";
10                super::measure_standard_text(
11                    known_dimensions,
12                    available_space,
13                    TEXT,
14                    super::WritingMode::Horizontal,
15                    None,
16                )
17            }),
18        )
19        .unwrap();
20    let node = taffy
21        .new_with_children(
22            taffy::style::Style {
23                display: taffy::style::Display::Grid,
24                grid_template_rows: vec![points(40f32)],
25                grid_template_columns: vec![fit_content(percent(0.5f32))],
26                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), height: auto() },
27                ..Default::default()
28            },
29            &[node0],
30        )
31        .unwrap();
32    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
33}