summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst/src/layout/stack.rs19
-rw-r--r--tests/ref/bugs/1240-stack-fr.pngbin0 -> 1197 bytes
-rw-r--r--tests/typ/bugs/1240-stack-fr.typ18
3 files changed, 35 insertions, 2 deletions
diff --git a/crates/typst/src/layout/stack.rs b/crates/typst/src/layout/stack.rs
index e1c26625..caa78264 100644
--- a/crates/typst/src/layout/stack.rs
+++ b/crates/typst/src/layout/stack.rs
@@ -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);
}
diff --git a/tests/ref/bugs/1240-stack-fr.png b/tests/ref/bugs/1240-stack-fr.png
new file mode 100644
index 00000000..29df5d44
--- /dev/null
+++ b/tests/ref/bugs/1240-stack-fr.png
Binary files differ
diff --git a/tests/typ/bugs/1240-stack-fr.typ b/tests/typ/bugs/1240-stack-fr.typ
new file mode 100644
index 00000000..fa49dce7
--- /dev/null
+++ b/tests/typ/bugs/1240-stack-fr.typ
@@ -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]),
+)