tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Definiciones

⎇ 39cd0fcbbda7cd38cc6316e7339b1f3aed29e99f examples/basic.rs Rust · 29 líneas · 878 B Historia Quién tocó qué crudo

Rename `new_node` to `new_with_children` (#142) 5d00d8fb9 · Andreas Weibye ·

1use taffy::prelude::*;
2
3fn main() -> Result<(), Error> {
4    let mut taffy = Taffy::new();
5
6    let child = taffy.new_with_children(
7        FlexboxLayout { size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto }, ..Default::default() },
8        &[],
9    )?;
10
11    let node = taffy.new_with_children(
12        FlexboxLayout {
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(node, Size { height: Number::Defined(100.0), width: Number::Defined(100.0) })?;
21
22    // or just use undefined for 100 x 100
23    // taffy.compute_layout(node, Size::undefined())?;
24
25    println!("node: {:#?}", taffy.layout(node)?);
26    println!("child: {:#?}", taffy.layout(child)?);
27
28    Ok(())
29}