tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Definiciones

add position support

2771b6b07155cb62177e354d98d5d9b88aa59463 · por Emil Sjölander · (hace 7 años) · padre 076aca1b7 · ver el árbol en este commit

Delta semántico · 5

src/algo.rs

src/style.rs

2 archivos · +37 −1

diff --git a/src/algo.rs b/src/algo.rs
index 2e8b9f0ba..e66a70ae9 100644
--- a/src/algo.rs
+++ b/src/algo.rs
@@ -864,13 +864,21 @@ fn compute_internal(
                 SizeConstraint::exactly(child.target_cross_size),
             );
 
-            let offset_main = { total_offset_main + child.offset_main + child.main_margin_start };
+            let offset_main = {
+                total_offset_main
+                    + child.offset_main
+                    + child.main_margin_start
+                    + (child.node.main_start().resolve(container_main_size, 0.0)
+                        - child.node.main_end().resolve(container_main_size, 0.0))
+            };
 
             let offset_cross = {
                 total_offset_cross
                     + child.offset_cross
                     + line.offset_cross
                     + child.cross_margin_start
+                    + (child.node.cross_start().resolve(container_main_size, 0.0)
+                        - child.node.cross_end().resolve(container_main_size, 0.0))
             };
 
             children.push(layout::Node {
diff --git a/src/style.rs b/src/style.rs
index a18d0be46..22f9bc2e3 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -402,6 +402,34 @@ impl Node {
         }
     }
 
+    pub(crate) fn main_start(&self) -> Dimension {
+        match self.flex_direction {
+            FlexDirection::Row | FlexDirection::RowReverse => self.start,
+            FlexDirection::Column | FlexDirection::ColumnReverse => self.top,
+        }
+    }
+
+    pub(crate) fn main_end(&self) -> Dimension {
+        match self.flex_direction {
+            FlexDirection::Row | FlexDirection::RowReverse => self.end,
+            FlexDirection::Column | FlexDirection::ColumnReverse => self.bottom,
+        }
+    }
+
+    pub(crate) fn cross_start(&self) -> Dimension {
+        match self.flex_direction {
+            FlexDirection::Row | FlexDirection::RowReverse => self.top,
+            FlexDirection::Column | FlexDirection::ColumnReverse => self.start,
+        }
+    }
+
+    pub(crate) fn cross_end(&self) -> Dimension {
+        match self.flex_direction {
+            FlexDirection::Row | FlexDirection::RowReverse => self.bottom,
+            FlexDirection::Column | FlexDirection::ColumnReverse => self.end,
+        }
+    }
+
     pub(crate) fn align_self(&self, parent: &Node) -> AlignSelf {
         if self.align_self == AlignSelf::Auto {
             match parent.align_items {