diff --git a/src/compute/block.rs b/src/compute/block.rs index 2d97bc03c..f1b601efe 100644 --- a/src/compute/block.rs +++ b/src/compute/block.rs @@ -446,6 +446,7 @@ fn perform_final_layout_on_in_flow_children( location, padding: item.padding, border: item.border, + margin: resolved_margin, }, ); @@ -674,6 +675,7 @@ fn perform_absolute_layout_on_absolute_children( location, padding, border, + margin: resolved_margin, }, ); diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index f87c0bc5e..3392759c9 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -1835,6 +1835,7 @@ fn calculate_flex_item( location, padding: item.padding, border: item.border, + margin: item.margin, }, ); @@ -2168,6 +2169,7 @@ fn perform_absolute_layout_on_absolute_children( location, padding, border, + margin: resolved_margin, }, ); diff --git a/src/compute/grid/alignment.rs b/src/compute/grid/alignment.rs index ad2bbf48b..8fe72fa04 100644 --- a/src/compute/grid/alignment.rs +++ b/src/compute/grid/alignment.rs @@ -190,7 +190,7 @@ pub(super) fn align_and_position_item( // Resolve final size let Size { width, height } = Size { width, height }.unwrap_or(layout_output.size).maybe_clamp(min_size, max_size); - let x = align_item_within_area( + let (x, x_margin) = align_item_within_area( Line { start: grid_area.left, end: grid_area.right }, justify_self.unwrap_or(alignment_styles.horizontal), width, @@ -199,7 +199,7 @@ pub(super) fn align_and_position_item( margin.horizontal_components(), 0.0, ); - let y = align_item_within_area( + let (y, y_margin) = align_item_within_area( Line { start: grid_area.top, end: grid_area.bottom }, align_self.unwrap_or(alignment_styles.vertical), height, @@ -214,6 +214,8 @@ pub(super) fn align_and_position_item( height: if overflow.x == Overflow::Scroll { scrollbar_width } else { 0.0 }, }; + let resolved_margin = Rect { left: x_margin.start, right: x_margin.end, top: y_margin.start, bottom: y_margin.end }; + tree.set_unrounded_layout( node, &Layout { @@ -225,6 +227,7 @@ pub(super) fn align_and_position_item( scrollbar_size, padding, border, + margin: resolved_margin, }, ); @@ -246,7 +249,7 @@ pub(super) fn align_item_within_area( inset: Line>, margin: Line>, baseline_shim: f32, -) -> f32 { +) -> (f32, Line) { // Calculate grid area dimension in the axis let non_auto_margin = Line { start: margin.start.unwrap_or(0.0) + baseline_shim, end: margin.end.unwrap_or(0.0) }; let grid_area_size = f32_max(grid_area.end - grid_area.start, 0.0); @@ -287,5 +290,5 @@ pub(super) fn align_item_within_area( start += inset.start.or(inset.end.map(|pos| -pos)).unwrap_or(0.0); } - start + (start, resolved_margin) } diff --git a/src/compute/mod.rs b/src/compute/mod.rs index 8b9584012..2392777e6 100644 --- a/src/compute/mod.rs +++ b/src/compute/mod.rs @@ -131,6 +131,8 @@ pub fn compute_root_layout(tree: &mut impl LayoutPartialTree, root: NodeId, avai scrollbar_size, padding, border, + // TODO: support auto margins for root node? + margin, }, ); } diff --git a/src/tree/layout.rs b/src/tree/layout.rs index 94c135766..24946ddc7 100644 --- a/src/tree/layout.rs +++ b/src/tree/layout.rs @@ -243,6 +243,8 @@ pub struct Layout { pub border: Rect, /// The size of the padding of the node pub padding: Rect, + /// The size of the margin of the node + pub margin: Rect, } impl Default for Layout { @@ -268,6 +270,7 @@ impl Layout { scrollbar_size: Size::zero(), border: Rect::zero(), padding: Rect::zero(), + margin: Rect::zero(), } } @@ -286,6 +289,7 @@ impl Layout { scrollbar_size: Size::zero(), border: Rect::zero(), padding: Rect::zero(), + margin: Rect::zero(), } } }