⎇ 832e2da45631009be13279a06c30f09962db0688
examples/nested.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Cleanup `new_with_children()` uses (#194)
1use taffy::prelude::*;
2
3fn main() -> Result<(), taffy::error::InvalidNode> {
4 let mut taffy = Taffy::new();
5
6 // left
7 let child_t1 = taffy.new_leaf(FlexboxLayout {
8 size: Size { width: Dimension::Points(5.0), height: Dimension::Points(5.0) },
9 ..Default::default()
10 })?;
11
12 let div1 = taffy.new_with_children(
13 FlexboxLayout {
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_leaf(FlexboxLayout {
23 size: Size { width: Dimension::Points(5.0), height: Dimension::Points(5.0) },
24 ..Default::default()
25 })?;
26
27 let div2 = taffy.new_with_children(
28 FlexboxLayout {
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_with_children(
37 FlexboxLayout {
38 size: Size { width: Dimension::Percent(1.0), height: Dimension::Percent(1.0) },
39 ..Default::default()
40 },
41 &[div1, div2],
42 )?;
43
44 taffy.compute_layout(container, Size { height: Some(100.0), width: Some(100.0) })?;
45
46 println!("node: {:#?}", taffy.layout(container)?);
47
48 println!("div1: {:#?}", taffy.layout(div1)?);
49 println!("div2: {:#?}", taffy.layout(div2)?);
50
51 println!("child1: {:#?}", taffy.layout(child_t1)?);
52 println!("child2: {:#?}", taffy.layout(child_t2)?);
53
54 Ok(())
55}