gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Definiciones

⎇ 0.2.x examples/basic.rs Rust · 32 líneas · 898 B Historia Quién tocó qué crudo

Rename FlexboxLayout back to Style (#251) 49893a7d9 · 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: 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}