gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Sutichaykuna

update readme and box measurte

d1d357f2a316aca030e9820a02ef33110c38e4f3 · ruwaq Emil Sjölander · (7 wata ñawpaq) · tayta a5d51d4e4 · kay commitpi sach'ata qhaway

Semántico sayk'uy · 17

src/algo.rs

src/style.rs

  • silq'uyninpi t'ikrakurqan struct Node pub
  • silq'uyninpi t'ikrakurqan fn default

tests/measure.rs

4 qillqakuna · +48 −45

diff --git a/README.md b/README.md
index c2b330dab..4ec3c2ed9 100644
--- a/README.md
+++ b/README.md
@@ -48,17 +48,20 @@ brew cask install chromedriver
 ## Contributing
 Constributions are very welcome. Though we ask that you open an issue or pull request early in the process (before writing code) so we can discuss solutions and additions before you start spending time on implementing them. There are some specific areas where we would be extra happy to recieve contributions in.
 
-- [ ] Binary size reduction
-- [ ] Runtime performance
-- [ ] Benchmark tests
-- [ ] Ensure build / test environment works well on non macOS platforms
-- [ ] Alternate layout systems
-- [ ] Web compatibility tests
-- [ ] RTL support
-- [ ] Incremental layout support
-- [ ] Android platform bindings
-- [ ] iOS platform bindings
-- [ ] JavaScript platform bindings
+- Binary size reduction
+- Runtime performance
+- Benchmark tests
+- Ensure build / test environment works well on non macOS platforms
+- Alternate layout systems
+- Web compatibility tests
+- RTL support
+- Incremental layout support
+
+**NOTICE** The library's API is currently very experimental so we won't be accepting any contributions which put a dependency on a stable API such as platform bindings. Once stabalized we would love contributions to the core repo for platform bindings such as.
+
+- Android platform bindings
+- iOS platform bindings
+- JavaScript platform bindings
 
 ## Relationship to Yoga
 [Yoga](https://www.yogalayout.com) is a cross-platform implementation of Flebox written in C. Yoga is a fantastic project but has some fundamental issues which we hope to resolve. Compared to Yoga we aim to have a stronger adherence to web standards, a flexible architecture supporting multiple layout algorithms, and performance improvements including multi-threaded layout. In addition to this we aim to use a safer language with a more modern codebase.
diff --git a/src/algo.rs b/src/algo.rs
index cef43ba1b..d7010b2e3 100644
--- a/src/algo.rs
+++ b/src/algo.rs
@@ -18,7 +18,7 @@ struct ComputeResult {
 }
 
 struct FlexItem<'a> {
-    node: &'a style::Node<'a>,
+    node: &'a style::Node,
 
     size: Size<Number>,
     min_size: Size<Number>,
@@ -118,7 +118,7 @@ fn compute_internal(
             return ComputeResult { size: node_size.map(|s| s.or_else(0.0)), children: vec![] };
         }
 
-        if let Some(measure) = node.measure {
+        if let Some(ref measure) = node.measure {
             return ComputeResult { size: measure(node_size), children: vec![] };
         }
     }
diff --git a/src/style.rs b/src/style.rs
index 4d0342b4a..e80b4a4c8 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -191,7 +191,7 @@ impl Default for Size<Dimension> {
     }
 }
 
-pub struct Node<'a> {
+pub struct Node {
     pub display: Display,
 
     pub position_type: PositionType,
@@ -221,13 +221,13 @@ pub struct Node<'a> {
     pub max_size: Size<Dimension>,
 
     pub aspect_ratio: Number,
-    pub measure: Option<&'a Fn(Size<Number>) -> Size<f32>>,
+    pub measure: Option<Box<Fn(Size<Number>) -> Size<f32>>>,
 
-    pub children: Vec<Node<'a>>,
+    pub children: Vec<Node>,
 }
 
-impl<'a> Default for Node<'a> {
-    fn default() -> Node<'a> {
+impl Default for Node {
+    fn default() -> Node {
         Node {
             display: Default::default(),
 
@@ -265,7 +265,7 @@ impl<'a> Default for Node<'a> {
     }
 }
 
-impl<'a> Node<'a> {
+impl Node {
     pub(crate) fn min_main_size(&self, direction: FlexDirection) -> Dimension {
         match direction {
             FlexDirection::Row | FlexDirection::RowReverse => self.min_size.width,
diff --git a/tests/measure.rs b/tests/measure.rs
index 5de2ca0a8..02cdfc6d3 100644
--- a/tests/measure.rs
+++ b/tests/measure.rs
@@ -5,10 +5,10 @@ mod measure {
     #[test]
     fn measure_root() {
         let layout = stretch::compute(&stretch::style::Node {
-            measure: Some(&|constraint| stretch::geometry::Size {
+            measure: Some(Box::new(|constraint| stretch::geometry::Size {
                 width: constraint.width.or_else(100.0),
                 height: constraint.height.or_else(100.0),
-            }),
+            })),
             ..Default::default()
         });
 
@@ -20,10 +20,10 @@ mod measure {
     fn measure_child() {
         let layout = stretch::compute(&stretch::style::Node {
             children: vec![stretch::style::Node {
-                measure: Some(&|constraint| stretch::geometry::Size {
+                measure: Some(Box::new(|constraint| stretch::geometry::Size {
                     width: constraint.width.or_else(100.0),
                     height: constraint.height.or_else(100.0),
-                }),
+                })),
                 ..Default::default()
             }],
             ..Default::default()
@@ -41,10 +41,10 @@ mod measure {
         let layout = stretch::compute(&stretch::style::Node {
             size: stretch::geometry::Size { width: stretch::style::Dimension::Points(50.0), ..Default::default() },
             children: vec![stretch::style::Node {
-                measure: Some(&|constraint| stretch::geometry::Size {
+                measure: Some(Box::new(|constraint| stretch::geometry::Size {
                     width: constraint.width.or_else(100.0),
                     height: constraint.height.or_else(100.0),
-                }),
+                })),
                 ..Default::default()
             }],
             ..Default::default()
@@ -68,10 +68,10 @@ mod measure {
                 bottom: stretch::style::Dimension::Points(10.0),
             },
             children: vec![stretch::style::Node {
-                measure: Some(&|constraint| stretch::geometry::Size {
+                measure: Some(Box::new(|constraint| stretch::geometry::Size {
                     width: constraint.width.or_else(100.0),
                     height: constraint.height.or_else(100.0),
-                }),
+                })),
                 ..Default::default()
             }],
             ..Default::default()
@@ -97,10 +97,10 @@ mod measure {
                     ..Default::default()
                 },
                 stretch::style::Node {
-                    measure: Some(&|constraint| stretch::geometry::Size {
+                    measure: Some(Box::new(|constraint| stretch::geometry::Size {
                         width: constraint.width.or_else(10.0),
                         height: constraint.height.or_else(50.0),
-                    }),
+                    })),
                     flex_grow: 1.0,
                     ..Default::default()
                 },
@@ -126,10 +126,10 @@ mod measure {
                     ..Default::default()
                 },
                 stretch::style::Node {
-                    measure: Some(&|constraint| stretch::geometry::Size {
+                    measure: Some(Box::new(|constraint| stretch::geometry::Size {
                         width: constraint.width.or_else(100.0),
                         height: constraint.height.or_else(50.0),
-                    }),
+                    })),
                     ..Default::default()
                 },
             ],
@@ -154,11 +154,11 @@ mod measure {
                     ..Default::default()
                 },
                 stretch::style::Node {
-                    measure: Some(&|constraint| {
+                    measure: Some(Box::new(|constraint| {
                         let width = constraint.width.or_else(10.0);
                         let height = constraint.height.or_else(width * 2.0);
                         stretch::geometry::Size { width, height }
-                    }),
+                    })),
                     flex_grow: 1.0,
                     ..Default::default()
                 },
@@ -185,11 +185,11 @@ mod measure {
                     ..Default::default()
                 },
                 stretch::style::Node {
-                    measure: Some(&|constraint| {
+                    measure: Some(Box::new(|constraint| {
                         let width = constraint.width.or_else(100.0);
                         let height = constraint.height.or_else(width * 2.0);
                         stretch::geometry::Size { width, height }
-                    }),
+                    })),
                     ..Default::default()
                 },
             ],
@@ -205,10 +205,10 @@ mod measure {
         let layout = stretch::compute(&stretch::style::Node {
             children: vec![stretch::style::Node {
                 size: stretch::geometry::Size { width: stretch::style::Dimension::Points(50.0), ..Default::default() },
-                measure: Some(&|constraint| stretch::geometry::Size {
+                measure: Some(Box::new(|constraint| stretch::geometry::Size {
                     width: constraint.width.or_else(100.0),
                     height: constraint.height.or_else(100.0),
-                }),
+                })),
                 ..Default::default()
             }],
             ..Default::default()
@@ -223,10 +223,10 @@ mod measure {
         let layout = stretch::compute(&stretch::style::Node {
             children: vec![stretch::style::Node {
                 size: stretch::geometry::Size { height: stretch::style::Dimension::Points(50.0), ..Default::default() },
-                measure: Some(&|constraint| stretch::geometry::Size {
+                measure: Some(Box::new(|constraint| stretch::geometry::Size {
                     width: constraint.width.or_else(100.0),
                     height: constraint.height.or_else(100.0),
-                }),
+                })),
                 ..Default::default()
             }],
             ..Default::default()
@@ -252,10 +252,10 @@ mod measure {
                 stretch::style::Node {
                     flex_basis: stretch::style::Dimension::Points(50.0),
                     flex_grow: 1.0,
-                    measure: Some(&|constraint| stretch::geometry::Size {
+                    measure: Some(Box::new(|constraint| stretch::geometry::Size {
                         width: constraint.width.or_else(100.0),
                         height: constraint.height.or_else(100.0),
-                    }),
+                    })),
                     ..Default::default()
                 },
             ],
@@ -276,10 +276,10 @@ mod measure {
                 height: stretch::style::Dimension::Points(100.0),
             },
             children: vec![stretch::style::Node {
-                measure: Some(&|constraint| stretch::geometry::Size {
+                measure: Some(Box::new(|constraint| stretch::geometry::Size {
                     width: constraint.width.or_else(50.0),
                     height: constraint.height.or_else(50.0),
-                }),
+                })),
                 ..Default::default()
             }],
             ..Default::default()
@@ -298,10 +298,10 @@ mod measure {
             },
             children: vec![stretch::style::Node {
                 position_type: stretch::style::PositionType::Absolute,
-                measure: Some(&|constraint| stretch::geometry::Size {
+                measure: Some(Box::new(|constraint| stretch::geometry::Size {
                     width: constraint.width.or_else(50.0),
                     height: constraint.height.or_else(50.0),
-                }),
+                })),
                 ..Default::default()
             }],
             ..Default::default()