gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Definiciones

⎇ 0.1.x examples/nested.rs Rust · 52 líneas · 1.5 KB Historia Quién tocó qué crudo

Rename sprawl to taffy (#134) 8936790d6 · Alice Cecile ·

1use taffy::prelude::*;
2
3fn main() -> Result<(), Error> {
4    let mut taffy = Taffy::new();
5
6    // left
7    let child_t1 = taffy.new_node(
8        Style { size: Size { width: Dimension::Points(5.0), height: Dimension::Points(5.0) }, ..Default::default() },
9        &[],
10    )?;
11
12    let div1 = taffy.new_node(
13        Style {
14            size: Size { width: Dimension::Percent(0.5), height: Dimension::Percent(1.0) },
15            // justify_content: JustifyContent::Center,
16            ..Default::default()
17        },
18        &[child_t1],
19    )?;
20
21    // right
22    let child_t2 = taffy.new_node(
23        Style { size: Size { width: Dimension::Points(5.0), height: Dimension::Points(5.0) }, ..Default::default() },
24        &[],
25    )?;
26
27    let div2 = taffy.new_node(
28        Style {
29            size: Size { width: Dimension::Percent(0.5), height: Dimension::Percent(1.0) },
30            // justify_content: JustifyContent::Center,
31            ..Default::default()
32        },
33        &[child_t2],
34    )?;
35
36    let container = taffy.new_node(
37        Style { size: Size { width: Dimension::Percent(1.0), height: Dimension::Percent(1.0) }, ..Default::default() },
38        &[div1, div2],
39    )?;
40
41    taffy.compute_layout(container, Size { height: Number::Defined(100.0), width: Number::Defined(100.0) })?;
42
43    println!("node: {:#?}", taffy.layout(container)?);
44
45    println!("div1: {:#?}", taffy.layout(div1)?);
46    println!("div2: {:#?}", taffy.layout(div2)?);
47
48    println!("child1: {:#?}", taffy.layout(child_t1)?);
49    println!("child2: {:#?}", taffy.layout(child_t2)?);
50
51    Ok(())
52}