gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 254C 19JavaScript 81371 Sutichaykuna

⎇ b91874d4e34ecc9054b468a338ffcae6f61a1b4a benches/generated/grid_margins_fixed_start.rs Rust · 45 siq'ikuna · 2.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

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
6        .new_leaf(taffy::style::Style {
7            align_self: Some(taffy::style::AlignSelf::Start),
8            justify_self: Some(taffy::style::JustifySelf::Start),
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Points(20f32),
11                height: taffy::style::Dimension::Points(20f32),
12            },
13            margin: taffy::geometry::Rect {
14                left: taffy::style::LengthPercentageAuto::Points(4f32),
15                right: taffy::style::LengthPercentageAuto::Points(2f32),
16                top: taffy::style::LengthPercentageAuto::Points(1f32),
17                bottom: taffy::style::LengthPercentageAuto::Points(3f32),
18            },
19            ..Default::default()
20        })
21        .unwrap();
22    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
23    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
24    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
25    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
26    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
27    let node = taffy
28        .new_with_children(
29            taffy::style::Style {
30                display: taffy::style::Display::Grid,
31                grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
32                grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
33                padding: taffy::geometry::Rect {
34                    left: taffy::style::LengthPercentage::Points(40f32),
35                    right: taffy::style::LengthPercentage::Points(20f32),
36                    top: taffy::style::LengthPercentage::Points(10f32),
37                    bottom: taffy::style::LengthPercentage::Points(30f32),
38                },
39                ..Default::default()
40            },
41            &[node0, node1, node2, node3, node4, node5],
42        )
43        .unwrap();
44    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
45}