Fix h
and v
in stack (#3423)
This commit is contained in:
parent
aabb4b5ecf
commit
1d78c3ed43
@ -4,8 +4,8 @@ use crate::diag::SourceResult;
|
||||
use crate::engine::Engine;
|
||||
use crate::foundations::{cast, elem, Content, Packed, Resolve, StyleChain, StyledElem};
|
||||
use crate::layout::{
|
||||
Abs, AlignElem, Axes, Axis, Dir, FixedAlignment, Fr, Fragment, Frame, LayoutMultiple,
|
||||
Point, Regions, Size, Spacing,
|
||||
Abs, AlignElem, Axes, Axis, Dir, FixedAlignment, Fr, Fragment, Frame, HElem,
|
||||
LayoutMultiple, Point, Regions, Size, Spacing, VElem,
|
||||
};
|
||||
use crate::util::{Get, Numeric};
|
||||
|
||||
@ -60,6 +60,7 @@ impl LayoutMultiple for Packed<StackElem> {
|
||||
regions: Regions,
|
||||
) -> SourceResult<Fragment> {
|
||||
let mut layouter = StackLayouter::new(self.dir(styles), regions, styles);
|
||||
let axis = layouter.dir.axis();
|
||||
|
||||
// Spacing to insert before the next block.
|
||||
let spacing = self.spacing(styles);
|
||||
@ -72,6 +73,20 @@ impl LayoutMultiple for Packed<StackElem> {
|
||||
deferred = None;
|
||||
}
|
||||
StackChild::Block(block) => {
|
||||
// Transparently handle `h`.
|
||||
if let (Axis::X, Some(h)) = (axis, block.to_packed::<HElem>()) {
|
||||
layouter.layout_spacing(*h.amount());
|
||||
deferred = None;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Transparently handle `v`.
|
||||
if let (Axis::Y, Some(v)) = (axis, block.to_packed::<VElem>()) {
|
||||
layouter.layout_spacing(*v.amount());
|
||||
deferred = None;
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(kind) = deferred {
|
||||
layouter.layout_spacing(kind);
|
||||
}
|
||||
|
BIN
tests/ref/bugs/1240-stack-fr.png
Normal file
BIN
tests/ref/bugs/1240-stack-fr.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
18
tests/typ/bugs/1240-stack-fr.typ
Normal file
18
tests/typ/bugs/1240-stack-fr.typ
Normal file
@ -0,0 +1,18 @@
|
||||
// This issue is sort of horrible: When you write `h(1fr)` in a `stack` instead
|
||||
// of directly `1fr`, things go awry. To fix this, we now transparently detect
|
||||
// h/v children.
|
||||
//
|
||||
// https://github.com/typst/typst/issues/1240
|
||||
|
||||
---
|
||||
#stack(dir: ltr, [a], 1fr, [b], 1fr, [c])
|
||||
#stack(dir: ltr, [a], h(1fr), [b], h(1fr), [c])
|
||||
|
||||
---
|
||||
#set page(height: 60pt)
|
||||
#stack(
|
||||
dir: ltr,
|
||||
spacing: 1fr,
|
||||
stack([a], 1fr, [b]),
|
||||
stack([a], v(1fr), [b]),
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user