tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Definitions

⎇ 6652882a96948b4d8ee433a176d428cf3c3916bf benches/generated/grid_absolute_container_top_bottom.rs Rust · 43 lines · 2.1 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
6        .new_leaf(taffy::style::Style {
7            position_type: taffy::style::PositionType::Absolute,
8            position: taffy::geometry::Rect {
9                left: auto(),
10                right: auto(),
11                top: taffy::style::LengthPercentageAuto::Points(2f32),
12                bottom: taffy::style::LengthPercentageAuto::Points(5f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18    let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19    let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
20    let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
21    let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
22    let node6 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
23    let node7 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
24    let node8 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
25    let node = taffy
26        .new_with_children(
27            taffy::style::Style {
28                display: taffy::style::Display::Grid,
29                grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
30                grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
31                padding: taffy::geometry::Rect {
32                    left: taffy::style::LengthPercentage::Points(40f32),
33                    right: taffy::style::LengthPercentage::Points(20f32),
34                    top: taffy::style::LengthPercentage::Points(10f32),
35                    bottom: taffy::style::LengthPercentage::Points(30f32),
36                },
37                ..Default::default()
38            },
39            &[node0, node1, node2, node3, node4, node5, node6, node7, node8],
40        )
41        .unwrap();
42    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
43}