tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Sutichaykuna

⎇ 0.4.x examples/basic.rs Rust · 34 siq'ikuna · 1.1 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1use taffy::prelude::*;
2
3fn main() -> Result<(), taffy::TaffyError> {
4    let mut taffy: TaffyTree<()> = TaffyTree::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::Length(100.0), height: Dimension::Length(100.0) },
14            justify_content: Some(JustifyContent::Center),
15            ..Default::default()
16        },
17        &[child],
18    )?;
19
20    println!("Compute layout with 100x100 viewport:");
21    taffy.compute_layout(
22        node,
23        Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
24    )?;
25    println!("node: {:#?}", taffy.layout(node)?);
26    println!("child: {:#?}", taffy.layout(child)?);
27
28    println!("Compute layout with undefined (infinite) viewport:");
29    taffy.compute_layout(node, Size::MAX_CONTENT)?;
30    println!("node: {:#?}", taffy.layout(node)?);
31    println!("child: {:#?}", taffy.layout(child)?);
32
33    Ok(())
34}