tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definiciones

fix: pass run_moade through layout

Root cause: Taffy's block layout had two places where it called PerformLayout on children when it only needed sizing information, causing descendant layouts to be overwritten with values computed at the wrong width.

Fix 1 — determine_content_based_container_width (line 632): Changed tree.perform_child_layout to tree.measure_child_size. This function only needs the child's width to determine the container's intrinsic width — it was needlessly doing full PerformLayout, which cascaded down and overwrote correct layouts.

Fix 2 — perform_final_layout_on_in_flow_children (line 846): Propagated the parent's run_mode to children instead of hardcoding PerformLayout. When a parent block is in ComputeSize mode, children now also get ComputeSize, preventing them from storing intermediate layout results. Also guarded set_unrounded_layout to only run in PerformLayout mode.

Result: node=31 (version selector) now correctly gets h=41 (matching Chrome), and the nav starts at y=49 instead of y=82, eliminating the 33px gap. All 4,380 Taffy tests pass.

b116057a7bb89ef653e26bb60b4b2ff5ae050fb9 · por Jonathan Kelley · (hace 7 meses) · padre f9514f685 · ver el árbol en este commit

Delta semántico · 3

src/compute/block.rs

1 archivos · +24 −21

diff --git a/src/compute/block.rs b/src/compute/block.rs
index 660b485e9..c6c4a17d6 100644
--- a/src/compute/block.rs
+++ b/src/compute/block.rs
@@ -10,8 +10,8 @@ use crate::util::sys::Vec;
 use crate::util::MaybeMath;
 use crate::util::{MaybeResolve, ResolveOrZero};
 use crate::{
-    BlockContainerStyle, BlockItemStyle, BoxGenerationMode, BoxSizing, Direction, LayoutBlockContainer, RequestedAxis,
-    TextAlign,
+    AbsoluteAxis, BlockContainerStyle, BlockItemStyle, BoxGenerationMode, BoxSizing, Direction, LayoutBlockContainer,
+    RequestedAxis, TextAlign,
 };
 
 #[cfg(feature = "float_layout")]
@@ -448,6 +448,7 @@ fn compute_inner(
             direction,
             own_margins_collapse_with_children,
             block_ctx,
+            run_mode,
         );
 
     // Root BFCs contain floats
@@ -628,16 +629,15 @@ fn determine_content_based_container_width(
             .resolve_or_zero(available_space.width.into_option(), |val, basis| tree.calc(val, basis))
             .horizontal_axis_sum();
         let width = known_dimensions.width.unwrap_or_else(|| {
-            let size_and_baselines = tree.perform_child_layout(
+            tree.measure_child_size(
                 item.node_id,
                 known_dimensions,
                 Size::NONE,
                 available_space.map_width(|w| w.maybe_sub(item_x_margin_sum)),
                 SizingMode::InherentSize,
+                AbsoluteAxis::Horizontal,
                 Line::TRUE,
-            );
-
-            size_and_baselines.size.width
+            )
         });
 
         let width = f32_max(width, item.padding_border_sum.width) + item_x_margin_sum;
@@ -673,6 +673,7 @@ fn perform_final_layout_on_in_flow_children(
     direction: Direction,
     own_margins_collapse_with_children: Line<bool>,
     block_ctx: &mut BlockContext<'_>,
+    run_mode: RunMode,
 ) -> (Size<f32>, f32, CollapsibleMarginSet, CollapsibleMarginSet) {
     // Resolve container_inner_width for sizing child nodes using initial content_box_inset
     let container_inner_width = container_outer_width - resolved_content_box_inset.horizontal_axis_sum();
@@ -843,7 +844,7 @@ fn perform_final_layout_on_in_flow_children(
             //
 
             let inputs = LayoutInput {
-                run_mode: RunMode::PerformLayout,
+                run_mode,
                 sizing_mode: SizingMode::InherentSize,
                 axis: RequestedAxis::Both,
                 known_dimensions,
@@ -1002,20 +1003,22 @@ fn perform_final_layout_on_in_flow_children(
                 }
             }
 
-            tree.set_unrounded_layout(
-                item.node_id,
-                &Layout {
-                    order: item.order,
-                    size: item_layout.size,
-                    #[cfg(feature = "content_size")]
-                    content_size: item_layout.content_size,
-                    scrollbar_size,
-                    location,
-                    padding: item.padding,
-                    border: item.border,
-                    margin: resolved_margin,
-                },
-            );
+            if run_mode == RunMode::PerformLayout {
+                tree.set_unrounded_layout(
+                    item.node_id,
+                    &Layout {
+                        order: item.order,
+                        size: item_layout.size,
+                        #[cfg(feature = "content_size")]
+                        content_size: item_layout.content_size,
+                        scrollbar_size,
+                        location,
+                        padding: item.padding,
+                        border: item.border,
+                        margin: resolved_margin,
+                    },
+                );
+            }
 
             #[cfg(feature = "content_size")]
             {