tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definiciones

⎇ 39cd0fcbbda7cd38cc6316e7339b1f3aed29e99f examples/nested.rs Rust · 61 líneas · 1.7 KB 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    // left
7    let child_t1 = taffy.new_with_children(
8        FlexboxLayout {
9            size: Size { width: Dimension::Points(5.0), height: Dimension::Points(5.0) },
10            ..Default::default()
11        },
12        &[],
13    )?;
14
15    let div1 = taffy.new_with_children(
16        FlexboxLayout {
17            size: Size { width: Dimension::Percent(0.5), height: Dimension::Percent(1.0) },
18            // justify_content: JustifyContent::Center,
19            ..Default::default()
20        },
21        &[child_t1],
22    )?;
23
24    // right
25    let child_t2 = taffy.new_with_children(
26        FlexboxLayout {
27            size: Size { width: Dimension::Points(5.0), height: Dimension::Points(5.0) },
28            ..Default::default()
29        },
30        &[],
31    )?;
32
33    let div2 = taffy.new_with_children(
34        FlexboxLayout {
35            size: Size { width: Dimension::Percent(0.5), height: Dimension::Percent(1.0) },
36            // justify_content: JustifyContent::Center,
37            ..Default::default()
38        },
39        &[child_t2],
40    )?;
41
42    let container = taffy.new_with_children(
43        FlexboxLayout {
44            size: Size { width: Dimension::Percent(1.0), height: Dimension::Percent(1.0) },
45            ..Default::default()
46        },
47        &[div1, div2],
48    )?;
49
50    taffy.compute_layout(container, Size { height: Number::Defined(100.0), width: Number::Defined(100.0) })?;
51
52    println!("node: {:#?}", taffy.layout(container)?);
53
54    println!("div1: {:#?}", taffy.layout(div1)?);
55    println!("div2: {:#?}", taffy.layout(div2)?);
56
57    println!("child1: {:#?}", taffy.layout(child_t1)?);
58    println!("child2: {:#?}", taffy.layout(child_t2)?);
59
60    Ok(())
61}