Fix box in 100% width block

Fixes #2128
This commit is contained in:
Laurenz 2023-09-13 12:28:30 +02:00
parent 8927f3d572
commit 8fb225feb4
5 changed files with 21 additions and 6 deletions

View File

@ -266,6 +266,7 @@ fn realize_block<'a>(
// These elements implement `Layout` but still require a flow for
// proper layout.
if content.can::<dyn Layout>()
&& !content.is::<BoxElem>()
&& !content.is::<LineElem>()
&& !content.is::<RectElem>()
&& !content.is::<SquareElem>()

View File

@ -149,6 +149,12 @@ impl<'a, 'b, 'v> MathContext<'a, 'b, 'v> {
Ok(self.layout_fragment(elem)?.into_frame())
}
pub fn layout_box(&mut self, boxed: &BoxElem) -> SourceResult<Frame> {
Ok(boxed
.layout(self.vt, self.outer.chain(&self.local), self.regions)?
.into_frame())
}
pub fn layout_content(&mut self, content: &Content) -> SourceResult<Frame> {
Ok(content
.layout(self.vt, self.outer.chain(&self.local), self.regions)?

View File

@ -457,18 +457,20 @@ impl LayoutMath for Content {
return Ok(());
}
if let Some(boxed) = self.to::<BoxElem>() {
let frame = ctx.layout_box(boxed)?;
ctx.push(FrameFragment::new(ctx, frame).with_spaced(true));
return Ok(());
}
if let Some(elem) = self.with::<dyn LayoutMath>() {
return elem.layout_math(ctx);
}
let mut frame = ctx.layout_content(self)?;
if !frame.has_baseline() {
if self.is::<BoxElem>() {
frame.set_baseline(frame.height());
} else {
let axis = scaled!(ctx, axis_height);
frame.set_baseline(frame.height() / 2.0 + axis);
}
let axis = scaled!(ctx, axis_height);
frame.set_baseline(frame.height() / 2.0 + axis);
}
ctx.push(FrameFragment::new(ctx, frame).with_spaced(true));

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,6 @@
// Test box in 100% width block.
---
#block(width: 100%, fill: red, box("a box"))
#block(width: 100%, fill: red, [#box("a box") #box()])