tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 709HTML 662Markdown 12TOML 62348 Definitions

Make low-level layout algorithm functions public (#434)

* Make low-level layout algorithm functions public

* Add const constructor to NodeId

* Feature flag algorithm exports

a99dc54ca0de208012b0d7b1c0023489bfd1919c · by Nico Burns · (3 years ago) · parent 3bda64442 · browse the tree at this commit

Semantic delta · 4

src/compute/flexbox.rs

src/compute/grid/mod.rs

src/compute/mod.rs

src/tree.rs

  • new fn new pub

5 files · +14 −3

diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs
index 68a90eee7..2c87a7b39 100644
--- a/src/compute/flexbox.rs
+++ b/src/compute/flexbox.rs
@@ -21,7 +21,7 @@ use crate::tree::{LayoutTree, NodeId};
 use crate::debug::NODE_LOGGER;
 
 /// The public interface to Taffy's Flexbox algorithm implementation
-pub(crate) struct FlexboxAlgorithm;
+pub struct FlexboxAlgorithm;
 impl LayoutAlgorithm for FlexboxAlgorithm {
     const NAME: &'static str = "FLEXBOX";
 
diff --git a/src/compute/grid/mod.rs b/src/compute/grid/mod.rs
index e758c3e54..a99b6057b 100644
--- a/src/compute/grid/mod.rs
+++ b/src/compute/grid/mod.rs
@@ -34,7 +34,7 @@ mod types;
 mod util;
 
 /// The public interface to Taffy's CSS Grid algorithm implementation
-pub(crate) struct CssGridAlgorithm;
+pub struct CssGridAlgorithm;
 impl LayoutAlgorithm for CssGridAlgorithm {
     const NAME: &'static str = "CSS GRID";
 
diff --git a/src/compute/mod.rs b/src/compute/mod.rs
index ca85b4187..bde1b6a67 100644
--- a/src/compute/mod.rs
+++ b/src/compute/mod.rs
@@ -54,7 +54,7 @@ pub fn compute_layout(
 }
 
 /// A common interface that all Taffy layout algorithms conform to
-pub(crate) trait LayoutAlgorithm {
+pub trait LayoutAlgorithm {
     /// The name of the algorithm (mainly used for debug purposes)
     const NAME: &'static str;
 
diff --git a/src/lib.rs b/src/lib.rs
index 47b99498f..5072dc099 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,4 +42,9 @@ mod resolve;
 mod sys;
 
 pub use crate::compute::compute_layout;
+#[cfg(feature = "flexbox")]
+pub use crate::compute::flexbox::FlexboxAlgorithm;
+#[cfg(feature = "grid")]
+pub use crate::compute::grid::CssGridAlgorithm;
+pub use crate::compute::LayoutAlgorithm;
 pub use crate::node::Taffy;
diff --git a/src/tree.rs b/src/tree.rs
index fa7b8f182..857481e85 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -11,6 +11,12 @@ use slotmap::{DefaultKey, Key, KeyData};
 /// and u64 if needed.
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
 pub struct NodeId(u64);
+impl NodeId {
+    /// Create a new NodeId from a u64 value
+    pub const fn new(val: u64) -> Self {
+        Self(val)
+    }
+}
 
 impl From<u64> for NodeId {
     #[inline]