tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Sutichaykuna

⎇ 50e6ff85d532b7c5b479d43c04ed797960559e72 examples/basic.rs Rust · 32 siq'ikuna · 904 B Ñawpa willay Pi imata llamkarqan ch'uya

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

1use taffy::prelude::*;
2
3fn main() -> Result<(), taffy::error::TaffyError> {
4    let mut taffy = Taffy::new();
5
6    let child = taffy.new_leaf(Style {
7        size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto },
8        ..Default::default()
9    })?;
10
11    let node = taffy.new_with_children(
12        Style {
13            size: Size { width: Dimension::Points(100.0), height: Dimension::Points(100.0) },
14            justify_content: Some(JustifyContent::Center),
15            ..Default::default()
16        },
17        &[child],
18    )?;
19
20    taffy.compute_layout(
21        node,
22        Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
23    )?;
24
25    // or just use undefined for 100 x 100
26    // taffy.compute_layout(node, Size::NONE)?;
27
28    println!("node: {:#?}", taffy.layout(node)?);
29    println!("child: {:#?}", taffy.layout(child)?);
30
31    Ok(())
32}