summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-07-19 12:59:34 +0200
committerLaurenz <laurmaedje@gmail.com>2023-07-19 12:59:34 +0200
commitfa9e2c62379792c045288d1ab66f68c5a2e18c42 (patch)
treee6302c3c4f735a627e5a28fff833d9d149bc9f91 /crates
parent3dcd8e6e6beb8c410e55141ca4fbc840679a1f14 (diff)
Resolve `place` deltas relative to real container size
Diffstat (limited to 'crates')
-rw-r--r--crates/typst-library/src/layout/flow.rs11
-rw-r--r--crates/typst-library/src/layout/place.rs9
2 files changed, 11 insertions, 9 deletions
diff --git a/crates/typst-library/src/layout/flow.rs b/crates/typst-library/src/layout/flow.rs
index 930857e7..4ce78c94 100644
--- a/crates/typst-library/src/layout/flow.rs
+++ b/crates/typst-library/src/layout/flow.rs
@@ -134,6 +134,7 @@ enum FlowItem {
frame: Frame,
x_align: Align,
y_align: Smart<Option<Align>>,
+ delta: Axes<Rel<Abs>>,
float: bool,
clearance: Abs,
},
@@ -276,12 +277,13 @@ impl<'a> FlowLayouter<'a> {
let float = placed.float(styles);
let clearance = placed.clearance(styles);
let alignment = placed.alignment(styles);
+ let delta = Axes::new(placed.dx(styles), placed.dy(styles)).resolve(styles);
let x_align = alignment.map_or(Align::Center, |aligns| {
aligns.x.unwrap_or(GenAlign::Start).resolve(styles)
});
let y_align = alignment.map(|align| align.y.resolve(styles));
let frame = placed.layout(vt, styles, self.regions)?.into_frame();
- let item = FlowItem::Placed { frame, x_align, y_align, float, clearance };
+ let item = FlowItem::Placed { frame, x_align, y_align, delta, float, clearance };
self.layout_item(vt, item)
}
@@ -508,7 +510,7 @@ impl<'a> FlowLayouter<'a> {
offset += frame.height();
output.push_frame(pos, frame);
}
- FlowItem::Placed { frame, x_align, y_align, float, .. } => {
+ FlowItem::Placed { frame, x_align, y_align, delta, float, .. } => {
let x = x_align.position(size.x - frame.width());
let y = if float {
match y_align {
@@ -534,7 +536,10 @@ impl<'a> FlowLayouter<'a> {
}
};
- output.push_frame(Point::new(x, y), frame);
+ let pos = Point::new(x, y)
+ + delta.zip(size).map(|(d, s)| d.relative_to(s)).to_point();
+
+ output.push_frame(pos, frame);
}
FlowItem::Footnote(frame) => {
let y = size.y - footnote_height + footnote_offset;
diff --git a/crates/typst-library/src/layout/place.rs b/crates/typst-library/src/layout/place.rs
index 115e5107..95c042ff 100644
--- a/crates/typst-library/src/layout/place.rs
+++ b/crates/typst-library/src/layout/place.rs
@@ -115,12 +115,9 @@ impl Layout for PlaceElem {
.at(self.span());
}
- let child = self
- .body()
- .moved(Axes::new(self.dx(styles), self.dy(styles)))
- .aligned(
- alignment.unwrap_or_else(|| Axes::with_x(Some(Align::Center.into()))),
- );
+ let child = self.body().aligned(
+ alignment.unwrap_or_else(|| Axes::with_x(Some(Align::Center.into()))),
+ );
let pod = Regions::one(base, Axes::splat(false));
let frame = child.layout(vt, styles, pod)?.into_frame();