gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91841 Sutichaykuna

fix absolute layout when start/end not defined

97b3de87017aac3d5aa23b5bf912fc79656610c9 · ruwaq Emil Sjölander · (7 wata ñawpaq) · tayta eb88533f3 · kay commitpi sach'ata qhaway

Semántico sayk'uy · 2

src/algo.rs

tests/generated.rs

3 qillqakuna · +53 −2

diff --git a/src/algo.rs b/src/algo.rs
index ffd0940e2..9df68861b 100644
--- a/src/algo.rs
+++ b/src/algo.rs
@@ -1092,7 +1092,11 @@ fn compute_internal(
                 .resolve(container_width)
                 .maybe_max(child.min_size.width.resolve(container_width))
                 .maybe_min(child.max_size.width.resolve(container_width))
-                .or_else(container_width - start - end);
+                .or_else(if start.is_defined() && end.is_defined() {
+                    container_width - start - end
+                } else {
+                    Undefined
+                });
 
             let height = child
                 .size
@@ -1100,7 +1104,11 @@ fn compute_internal(
                 .resolve(container_height)
                 .maybe_max(child.min_size.height.resolve(container_height))
                 .maybe_min(child.max_size.height.resolve(container_height))
-                .or_else(container_height - top - bottom);
+                .or_else(if top.is_defined() && bottom.is_defined() {
+                    container_height - top - bottom
+                } else {
+                    Undefined
+                });
 
             let result = compute_internal(
                 child,
diff --git a/test_fixtures/absolute_layout_no_size.html b/test_fixtures/absolute_layout_no_size.html
new file mode 100644
index 000000000..3be0fc8e2
--- /dev/null
+++ b/test_fixtures/absolute_layout_no_size.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <script src="../scripts/gentest/test_helper.js"></script>
+  <link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
+  <title>
+    Test description
+  </title>
+<head/>
+<body>
+
+<div id="test-root" style="height: 100px; width: 100px;">
+  <div style="position: absolute;"></div>
+</div>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/tests/generated.rs b/tests/generated.rs
index 15e1acdea..03a18ea25 100644
--- a/tests/generated.rs
+++ b/tests/generated.rs
@@ -1935,6 +1935,32 @@ mod generated {
         assert_eq!(layout.children[0].location.y, 0.0000);
     }
 
+    #[test]
+    fn absolute_layout_no_size() {
+        let layout = stretch::compute(&stretch::style::Node {
+            size: stretch::geometry::Size {
+                width: stretch::style::Dimension::Points(100.0000),
+                height: stretch::style::Dimension::Points(100.0000),
+                ..Default::default()
+            },
+            children: vec![stretch::style::Node {
+                position_type: stretch::style::PositionType::Absolute,
+                ..Default::default()
+            }],
+            ..Default::default()
+        });
+
+        assert_eq!(layout.size.width, 100.0000);
+        assert_eq!(layout.size.height, 100.0000);
+        assert_eq!(layout.location.x, 0.0000);
+        assert_eq!(layout.location.y, 0.0000);
+
+        assert_eq!(layout.children[0].size.width, 0.0000);
+        assert_eq!(layout.children[0].size.height, 0.0000);
+        assert_eq!(layout.children[0].location.x, 0.0000);
+        assert_eq!(layout.children[0].location.y, 0.0000);
+    }
+
     #[test]
     fn border_flex_child() {
         let layout = stretch::compute(&stretch::style::Node {