forked from DioxusLabs/taffy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.rs
32 lines (25 loc) · 897 Bytes
/
basic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use taffy::prelude::*;
fn main() -> Result<(), taffy::TaffyError> {
let mut taffy = Taffy::new();
let child = taffy.new_leaf(Style {
size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto },
..Default::default()
})?;
let node = taffy.new_with_children(
Style {
size: Size { width: Dimension::Length(100.0), height: Dimension::Length(100.0) },
justify_content: Some(JustifyContent::Center),
..Default::default()
},
&[child],
)?;
taffy.compute_layout(
node,
Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
)?;
// or just use undefined for 100 x 100
// taffy.compute_layout(node, Size::NONE)?;
println!("node: {:#?}", taffy.layout(node)?);
println!("child: {:#?}", taffy.layout(child)?);
Ok(())
}