tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Sutichaykuna

⎇ 6652882a96948b4d8ee433a176d428cf3c3916bf benches/generated/grid_absolute_container_bottom_left_margin.rs Rust · 53 siq'ikuna · 2.7 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            position_type: taffy::style::PositionType::Absolute,
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Points(10f32),
10                height: taffy::style::Dimension::Points(10f32),
11            },
12            margin: taffy::geometry::Rect {
13                left: taffy::style::LengthPercentageAuto::Points(4f32),
14                right: taffy::style::LengthPercentageAuto::Points(2f32),
15                top: taffy::style::LengthPercentageAuto::Points(1f32),
16                bottom: taffy::style::LengthPercentageAuto::Points(3f32),
17            },
18            position: taffy::geometry::Rect {
19                left: taffy::style::LengthPercentageAuto::Points(0f32),
20                right: auto(),
21                top: auto(),
22                bottom: taffy::style::LengthPercentageAuto::Points(0f32),
23            },
24            ..Default::default()
25        })
26        .unwrap();
27    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
28    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
29    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
30    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
31    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
32    let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
33    let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
34    let node8 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
35    let node = taffy
36        .new_with_children(
37            taffy::style::Style {
38                display: taffy::style::Display::Grid,
39                grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
40                grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
41                padding: taffy::geometry::Rect {
42                    left: taffy::style::LengthPercentage::Points(40f32),
43                    right: taffy::style::LengthPercentage::Points(20f32),
44                    top: taffy::style::LengthPercentage::Points(10f32),
45                    bottom: taffy::style::LengthPercentage::Points(30f32),
46                },
47                ..Default::default()
48            },
49            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
50        )
51        .unwrap();
52    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
53}