tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 496HTML 245JavaScript 8CSS 61215 Definitions

⎇ ebd376fbebd0ba73c79aa00d1835918680ef82a0 benches/generated/grid_basic_with_padding.rs Rust · 32 lines · 1.8 KB History Who touched what raw

Implement CSS Grid (#205) 6fd2c6bcb · Nico Burns ·

1pub fn compute() {
2    #[allow(unused_imports)]
3    use taffy::prelude::*;
4    let mut taffy = taffy::Taffy::new();
5    let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
6    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
7    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
9    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
10    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
11    let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
12    let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
13    let node8 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
14    let node = taffy
15        .new_with_children(
16            taffy::style::Style {
17                display: taffy::style::Display::Grid,
18                grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
19                grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
20                padding: taffy::geometry::Rect {
21                    left: taffy::style::LengthPercentage::Points(40f32),
22                    right: taffy::style::LengthPercentage::Points(20f32),
23                    top: taffy::style::LengthPercentage::Points(10f32),
24                    bottom: taffy::style::LengthPercentage::Points(30f32),
25                },
26                ..Default::default()
27            },
28            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
29        )
30        .unwrap();
31    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
32}