Semantic delta · 1
examples/basic.rs
- signature changed fn main
diff --git a/benches/complex.rs b/benches/complex.rs
index 79611988e..181ba4a55 100644
--- a/benches/complex.rs
+++ b/benches/complex.rs
@@ -1,93 +1,109 @@
use criterion::{criterion_group, criterion_main, Criterion};
fn build_deep_hierarchy(stretch: &mut stretch::node::Stretch) -> stretch::node::Node {
- let node111 = stretch.new_node(
- stretch::style::Style {
- size: stretch::geometry::Size {
- width: stretch::style::Dimension::Points(10.0),
- height: stretch::style::Dimension::Points(10.0),
+ let node111 = stretch
+ .new_node(
+ stretch::style::Style {
+ size: stretch::geometry::Size {
+ width: stretch::style::Dimension::Points(10.0),
+ height: stretch::style::Dimension::Points(10.0),
+ },
+ ..Default::default()
},
- ..Default::default()
- },
- vec![],
- ).unwrap();
- let node112 = stretch.new_node(
- stretch::style::Style {
- size: stretch::geometry::Size {
- width: stretch::style::Dimension::Points(10.0),
- height: stretch::style::Dimension::Points(10.0),
+ vec![],
+ )
+ .unwrap();
+ let node112 = stretch
+ .new_node(
+ stretch::style::Style {
+ size: stretch::geometry::Size {
+ width: stretch::style::Dimension::Points(10.0),
+ height: stretch::style::Dimension::Points(10.0),
+ },
+ ..Default::default()
},
- ..Default::default()
- },
- vec![],
- ).unwrap();
+ vec![],
+ )
+ .unwrap();
- let node121 = stretch.new_node(
- stretch::style::Style {
- size: stretch::geometry::Size {
- width: stretch::style::Dimension::Points(10.0),
- height: stretch::style::Dimension::Points(10.0),
+ let node121 = stretch
+ .new_node(
+ stretch::style::Style {
+ size: stretch::geometry::Size {
+ width: stretch::style::Dimension::Points(10.0),
+ height: stretch::style::Dimension::Points(10.0),
+ },
+ ..Default::default()
},
- ..Default::default()
- },
- vec![],
- ).unwrap();
- let node122 = stretch.new_node(
- stretch::style::Style {
- size: stretch::geometry::Size {
- width: stretch::style::Dimension::Points(10.0),
- height: stretch::style::Dimension::Points(10.0),
+ vec![],
+ )
+ .unwrap();
+ let node122 = stretch
+ .new_node(
+ stretch::style::Style {
+ size: stretch::geometry::Size {
+ width: stretch::style::Dimension::Points(10.0),
+ height: stretch::style::Dimension::Points(10.0),
+ },
+ ..Default::default()
},
- ..Default::default()
- },
- vec![],
- ).unwrap();
+ vec![],
+ )
+ .unwrap();
let node11 = stretch.new_node(stretch::style::Style { ..Default::default() }, vec![node111, node112]).unwrap();
let node12 = stretch.new_node(stretch::style::Style { ..Default::default() }, vec![node121, node122]).unwrap();
let node1 = stretch.new_node(stretch::style::Style { ..Default::default() }, vec![node11, node12]).unwrap();
- let node211 = stretch.new_node(
- stretch::style::Style {
- size: stretch::geometry::Size {
- width: stretch::style::Dimension::Points(10.0),
- height: stretch::style::Dimension::Points(10.0),
+ let node211 = stretch
+ .new_node(
+ stretch::style::Style {
+ size: stretch::geometry::Size {
+ width: stretch::style::Dimension::Points(10.0),
+ height: stretch::style::Dimension::Points(10.0),
+ },
+ ..Default::default()
},
- ..Default::default()
- },
- vec![],
- ).unwrap();
- let node212 = stretch.new_node(
- stretch::style::Style {
- size: stretch::geometry::Size {
- width: stretch::style::Dimension::Points(10.0),
- height: stretch::style::Dimension::Points(10.0),
+ vec![],
+ )
+ .unwrap();
+ let node212 = stretch
+ .new_node(
+ stretch::style::Style {
+ size: stretch::geometry::Size {
+ width: stretch::style::Dimension::Points(10.0),
+ height: stretch::style::Dimension::Points(10.0),
+ },
+ ..Default::default()
},
- ..Default::default()
- },
- vec![],
- ).unwrap();
+ vec![],
+ )
+ .unwrap();
- let node221 = stretch.new_node(
- stretch::style::Style {
- size: stretch::geometry::Size {
- width: stretch::style::Dimension::Points(10.0),
- height: stretch::style::Dimension::Points(10.0),
+ let node221 = stretch
+ .new_node(
+ stretch::style::Style {
+ size: stretch::geometry::Size {
+ width: stretch::style::Dimension::Points(10.0),
+ height: stretch::style::Dimension::Points(10.0),
+ },
+ ..Default::default()
},
- ..Default::default()
- },
- vec![],
- ).unwrap();
- let node222 = stretch.new_node(
- stretch::style::Style {
- size: stretch::geometry::Size {
- width: stretch::style::Dimension::Points(10.0),
- height: stretch::style::Dimension::Points(10.0),
+ vec![],
+ )
+ .unwrap();
+ let node222 = stretch
+ .new_node(
+ stretch::style::Style {
+ size: stretch::geometry::Size {
+ width: stretch::style::Dimension::Points(10.0),
+ height: stretch::style::Dimension::Points(10.0),
+ },
+ ..Default::default()
},
- ..Default::default()
- },
- vec![],
- ).unwrap();
+ vec![],
+ )
+ .unwrap();
let node21 = stretch.new_node(stretch::style::Style { ..Default::default() }, vec![node211, node212]).unwrap();
let node22 = stretch.new_node(stretch::style::Style { ..Default::default() }, vec![node221, node222]).unwrap();
diff --git a/examples/basic.rs b/examples/basic.rs
index 3ba1ff4b7..86c7256a4 100644
--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -2,20 +2,24 @@ use stretch::geometry::Size;
use stretch::node::Node;
use stretch::style::*;
-fn main() {
- let node = Node::new(
+fn main() -> Result<(), stretch::Error> {
+ let mut stretch = stretch::node::Stretch::new();
+ let child = stretch.new_node(
+ Style { size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto }, ..Default::default() },
+ vec![],
+ )?;
+ let node = stretch.new_node(
Style {
size: Size { width: Dimension::Points(100.0), height: Dimension::Points(100.0) },
justify_content: JustifyContent::Center,
..Default::default()
},
- vec![&Node::new(
- Style { size: Size { width: Dimension::Percent(0.5), height: Dimension::Auto }, ..Default::default() },
- vec![],
- )],
- );
+ vec![child],
+ )?;
- let layout = node.compute_layout(Size::undefined()).unwrap();
+ stretch.compute_layout(node, Size::undefined())?;
+ println!("node: {:#?}", stretch.layout(node)?);
+ println!("child: {:#?}", stretch.layout(child)?);
- println!("{:#?}", layout);
+ Ok(())
}