gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

Lay out floats with definite available width (#994)

86023685f5f29e5a50e9d9dcfbbee302c2f6f7b1 · by Nico Burns · (2 months ago) · parent 86d93d95b · browse the tree at this commit

Semantic delta · 1

src/compute/block.rs

1 files · +4 −2

diff --git a/src/compute/block.rs b/src/compute/block.rs
index 21c511eff..a59f68879 100644
--- a/src/compute/block.rs
+++ b/src/compute/block.rs
@@ -822,12 +822,14 @@ fn perform_final_layout_on_in_flow_children(
             if let Some(float_direction) = item.float.float_direction() {
                 has_active_floats = true;
 
+                // A float with `width: auto` is shrink-to-fit (fit-content) sized: the available
+                // space clamped between its min-content and max-content sizes.
+                let available_width = container_inner_width - item_non_auto_x_margin_sum;
                 let item_layout = tree.perform_child_layout(
                     item.node_id,
                     Size::NONE,
                     parent_size,
-                    // available_space,
-                    Size::MAX_CONTENT,
+                    Size { width: AvailableSpace::Definite(available_width), height: AvailableSpace::MaxContent },
                     SizingMode::InherentSize,
                     Line::TRUE,
                 );