Delta semántico · 10
src/compute/taffy_tree.rs
diff --git a/src/compute/mod.rs b/src/compute/mod.rs
index 48946310f..134b2233c 100644
--- a/src/compute/mod.rs
+++ b/src/compute/mod.rs
@@ -14,6 +14,9 @@ pub(crate) mod flexbox;
#[cfg(feature = "grid")]
pub(crate) mod grid;
+#[cfg(feature = "morphorm")]
+pub(crate) mod morphorm;
+
use crate::geometry::{Line, Size};
use crate::style::AvailableSpace;
use crate::tree::{Layout, LayoutTree, NodeId, SizeBaselinesAndMargins, SizingMode};
@@ -27,6 +30,9 @@ pub use self::flexbox::FlexboxAlgorithm;
#[cfg(feature = "grid")]
pub use self::grid::CssGridAlgorithm;
+#[cfg(feature = "morphorm")]
+pub use self::morphorm::MorphormAlgorithm;
+
#[cfg(feature = "taffy_tree")]
pub(crate) mod taffy_tree;
diff --git a/src/compute/morphorm.rs b/src/compute/morphorm.rs
new file mode 100644
index 000000000..ad4a889f4
--- /dev/null
+++ b/src/compute/morphorm.rs
@@ -0,0 +1,89 @@
+use crate::compute::LayoutAlgorithm;
+use crate::geometry::{Line, Point, Rect, Size};
+use crate::style::{
+ AlignContent, AlignItems, AlignSelf, AvailableSpace, Dimension, Display, FlexWrap, JustifyContent,
+ LengthPercentageAuto, Position,
+};
+use crate::style::{FlexDirection, Style};
+use crate::tree::LayoutTree;
+use crate::tree::NodeId;
+use crate::tree::{Layout, RunMode, SizeBaselinesAndMargins, SizingMode};
+
+/// The public interface to Taffy's Flexbox algorithm implementation
+pub struct MorphormAlgorithm;
+impl LayoutAlgorithm for MorphormAlgorithm {
+ const NAME: &'static str = "MORPHORM";
+
+ fn perform_layout(
+ tree: &mut impl LayoutTree,
+ node: NodeId,
+ known_dimensions: Size<Option<f32>>,
+ parent_size: Size<Option<f32>>,
+ available_space: Size<AvailableSpace>,
+ _sizing_mode: SizingMode,
+ _vertical_margins_are_collapsible: Line<bool>,
+ ) -> SizeBaselinesAndMargins {
+ compute(tree, node, known_dimensions, parent_size, available_space, RunMode::PerformLayout)
+ }
+
+ fn measure_size(
+ tree: &mut impl LayoutTree,
+ node: NodeId,
+ known_dimensions: Size<Option<f32>>,
+ parent_size: Size<Option<f32>>,
+ available_space: Size<AvailableSpace>,
+ _sizing_mode: SizingMode,
+ _vertical_margins_are_collapsible: Line<bool>,
+ ) -> Size<f32> {
+ compute(tree, node, known_dimensions, parent_size, available_space, RunMode::ComputeSize).size
+ }
+}
+
+#[derive(Debug)]
+pub struct ChildNode {
+ // A reference to the node.
+ node: NodeId,
+ // The index of the node.
+ index: usize,
+
+ // The stretch factor of the node.
+ stretch_factor: Size<f32>,
+ // The minimum constraint of the node.
+ min: Size<Option<f32>>,
+ // The maximum constraint of the node.
+ max: Size<Option<f32>>,
+
+ // Sum of the flex factors on the main axis of the node.
+ main_flex_sum: f32,
+ // The available free space on the main axis of the node.
+ main_non_flex: f32,
+ // A remainder used during stretch computation.
+ main_remainder: f32,
+ // Sum of the cross_before, cross, and cross_after flex factors of the node.
+ cross_flex_sum: f32,
+
+ cross_non_flex: f32,
+ cross: f32,
+ cross_remainder: f32,
+
+ // Computed main-before space of the node.
+ main_before: f32,
+ // Computed main-after space of the node.
+ main_after: f32,
+ // Computed cross-before space of the node.
+ cross_before: f32,
+ // Computed cross-after space of the node.
+ cross_after: f32,
+}
+
+/// Computes the layout of [`LayoutTree`] according to the flexbox algorithm
+pub fn compute(
+ tree: &mut impl LayoutTree,
+ node: NodeId,
+ known_dimensions: Size<Option<f32>>,
+ parent_size: Size<Option<f32>>,
+ available_space: Size<AvailableSpace>,
+ run_mode: RunMode,
+) -> SizeBaselinesAndMargins {
+ Size::zero().into()
+}
diff --git a/src/compute/taffy_tree.rs b/src/compute/taffy_tree.rs
index d5cce7843..1511f56a3 100644
--- a/src/compute/taffy_tree.rs
+++ b/src/compute/taffy_tree.rs
@@ -17,6 +17,9 @@ use crate::compute::FlexboxAlgorithm;
#[cfg(feature = "grid")]
use crate::compute::CssGridAlgorithm;
+#[cfg(feature = "morphorm")]
+use crate::compute::MorphormAlgorithm;
+
#[cfg(any(feature = "debug", feature = "profile"))]
use crate::util::debug::NODE_LOGGER;
@@ -235,6 +238,17 @@ where
sizing_mode,
vertical_margins_are_collapsible,
),
+ #[cfg(feature = "morphorm")]
+ (Display::Morphorm, true) => perform_computations::<MorphormAlgorithm>(
+ taffy_view,
+ node,
+ known_dimensions,
+ parent_size,
+ available_space,
+ run_mode,
+ sizing_mode,
+ vertical_margins_are_collapsible,
+ ),
(_, false) => match run_mode {
RunMode::PerformLayout => leaf::perform_layout(
&taffy_view.taffy.nodes[node_key].style,
diff --git a/src/style/mod.rs b/src/style/mod.rs
index 16060124d..1ad9c892b 100644
--- a/src/style/mod.rs
+++ b/src/style/mod.rs
@@ -44,6 +44,9 @@ pub enum Display {
/// The children will follow the CSS Grid layout algorithm
#[cfg(feature = "grid")]
Grid,
+ /// The children will follow the Morphorm layout algorithm
+ #[cfg(feature = "morphorm")]
+ Morphorm,
/// The children will not be laid out, and will follow absolute positioning
None,
}
diff --git a/src/util/debug.rs b/src/util/debug.rs
index 5c257533a..f75ffd544 100644
--- a/src/util/debug.rs
+++ b/src/util/debug.rs
@@ -25,6 +25,8 @@ fn print_node(tree: &impl LayoutTree, node: NodeId, has_sibling: bool, lines_str
(_, style::Display::Flex) => "FLEX",
#[cfg(feature = "grid")]
(_, style::Display::Grid) => "GRID",
+ #[cfg(feature = "morphorm")]
+ (_, style::Display::Morphorm) => "MORPHORM",
};
let fork_string = if has_sibling { "├── " } else { "└── " };