tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

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

Prepare for release of new sprawl crate (#53) 7e84a464b · Alice Cecile ·

1use sprawl::prelude::*;
2
3fn main() -> Result<(), Error> {
4    let mut stretch = Stretch::new();
5
6    let child = stretch.new_node(
7        Style { size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto }, ..Default::default() },
8        &[],
9    )?;
10
11    let node = stretch.new_node(
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    stretch.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    // stretch.compute_layout(node, Size::undefined())?;
24
25    println!("node: {:#?}", stretch.layout(node)?);
26    println!("child: {:#?}", stretch.layout(child)?);
27
28    Ok(())
29}