gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definitions

Block: ignore margin collapsing when computing static position of abspos items (#747)

Signed-off-by: Nico Burns <nico@nicoburns.com>

fc91896e8f52daedd9464e0b137a2eb612d235e1 · by Nico Burns · (1 year ago) · parent 21e1cadf7 · browse the tree at this commit

Semantic delta · 1

src/compute/block.rs

1 files · +4 −1

diff --git a/src/compute/block.rs b/src/compute/block.rs
index eeb2aa009..db1eb8bdd 100644
--- a/src/compute/block.rs
+++ b/src/compute/block.rs
@@ -402,12 +402,13 @@ fn perform_final_layout_on_in_flow_children(
     #[cfg_attr(not(feature = "content_size"), allow(unused_mut))]
     let mut inflow_content_size = Size::ZERO;
     let mut committed_y_offset = resolved_content_box_inset.top;
+    let mut y_offset_for_absolute = resolved_content_box_inset.top;
     let mut first_child_top_margin_set = CollapsibleMarginSet::ZERO;
     let mut active_collapsible_margin_set = CollapsibleMarginSet::ZERO;
     let mut is_collapsing_with_first_margin_set = true;
     for item in items.iter_mut() {
         if item.position == Position::Absolute {
-            item.static_position = Point { x: resolved_content_box_inset.left, y: committed_y_offset }
+            item.static_position = Point { x: resolved_content_box_inset.left, y: y_offset_for_absolute }
         } else {
             let item_margin = item.margin.map(|margin| margin.resolve_to_option(container_outer_width));
             let item_non_auto_margin = item_margin.map(|m| m.unwrap_or(0.0));
@@ -547,8 +548,10 @@ fn perform_final_layout_on_in_flow_children(
                 active_collapsible_margin_set = active_collapsible_margin_set
                     .collapse_with_set(top_margin_set)
                     .collapse_with_set(bottom_margin_set);
+                y_offset_for_absolute = committed_y_offset + item_layout.size.height + y_margin_offset;
             } else {
                 committed_y_offset += item_layout.size.height + y_margin_offset;
+                y_offset_for_absolute = committed_y_offset;
                 active_collapsible_margin_set = bottom_margin_set;
             }
         }