Skip to content

Commit 514bbd4

Browse files
committed
Output computed margins in Layout
1 parent 1ed1d52 commit 514bbd4

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

src/compute/block.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ fn perform_final_layout_on_in_flow_children(
446446
location,
447447
padding: item.padding,
448448
border: item.border,
449+
margin: resolved_margin,
449450
},
450451
);
451452

@@ -674,6 +675,7 @@ fn perform_absolute_layout_on_absolute_children(
674675
location,
675676
padding,
676677
border,
678+
margin: resolved_margin,
677679
},
678680
);
679681

src/compute/flexbox.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,7 @@ fn calculate_flex_item(
18351835
location,
18361836
padding: item.padding,
18371837
border: item.border,
1838+
margin: item.margin,
18381839
},
18391840
);
18401841

@@ -2168,6 +2169,7 @@ fn perform_absolute_layout_on_absolute_children(
21682169
location,
21692170
padding,
21702171
border,
2172+
margin: resolved_margin,
21712173
},
21722174
);
21732175

src/compute/grid/alignment.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub(super) fn align_and_position_item(
190190
// Resolve final size
191191
let Size { width, height } = Size { width, height }.unwrap_or(layout_output.size).maybe_clamp(min_size, max_size);
192192

193-
let x = align_item_within_area(
193+
let (x, x_margin) = align_item_within_area(
194194
Line { start: grid_area.left, end: grid_area.right },
195195
justify_self.unwrap_or(alignment_styles.horizontal),
196196
width,
@@ -199,7 +199,7 @@ pub(super) fn align_and_position_item(
199199
margin.horizontal_components(),
200200
0.0,
201201
);
202-
let y = align_item_within_area(
202+
let (y, y_margin) = align_item_within_area(
203203
Line { start: grid_area.top, end: grid_area.bottom },
204204
align_self.unwrap_or(alignment_styles.vertical),
205205
height,
@@ -214,6 +214,8 @@ pub(super) fn align_and_position_item(
214214
height: if overflow.x == Overflow::Scroll { scrollbar_width } else { 0.0 },
215215
};
216216

217+
let resolved_margin = Rect { left: x_margin.start, right: x_margin.end, top: y_margin.start, bottom: y_margin.end };
218+
217219
tree.set_unrounded_layout(
218220
node,
219221
&Layout {
@@ -225,6 +227,7 @@ pub(super) fn align_and_position_item(
225227
scrollbar_size,
226228
padding,
227229
border,
230+
margin: resolved_margin,
228231
},
229232
);
230233

@@ -246,7 +249,7 @@ pub(super) fn align_item_within_area(
246249
inset: Line<Option<f32>>,
247250
margin: Line<Option<f32>>,
248251
baseline_shim: f32,
249-
) -> f32 {
252+
) -> (f32, Line<f32>) {
250253
// Calculate grid area dimension in the axis
251254
let non_auto_margin = Line { start: margin.start.unwrap_or(0.0) + baseline_shim, end: margin.end.unwrap_or(0.0) };
252255
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(
287290
start += inset.start.or(inset.end.map(|pos| -pos)).unwrap_or(0.0);
288291
}
289292

290-
start
293+
(start, resolved_margin)
291294
}

src/compute/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ pub fn compute_root_layout(tree: &mut impl LayoutPartialTree, root: NodeId, avai
131131
scrollbar_size,
132132
padding,
133133
border,
134+
// TODO: support auto margins for root node?
135+
margin,
134136
},
135137
);
136138
}

src/tree/layout.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ pub struct Layout {
243243
pub border: Rect<f32>,
244244
/// The size of the padding of the node
245245
pub padding: Rect<f32>,
246+
/// The size of the margin of the node
247+
pub margin: Rect<f32>,
246248
}
247249

248250
impl Default for Layout {
@@ -268,6 +270,7 @@ impl Layout {
268270
scrollbar_size: Size::zero(),
269271
border: Rect::zero(),
270272
padding: Rect::zero(),
273+
margin: Rect::zero(),
271274
}
272275
}
273276

@@ -286,6 +289,7 @@ impl Layout {
286289
scrollbar_size: Size::zero(),
287290
border: Rect::zero(),
288291
padding: Rect::zero(),
292+
margin: Rect::zero(),
289293
}
290294
}
291295
}

0 commit comments

Comments
 (0)