mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Resolve place
deltas relative to real container size
This commit is contained in:
parent
3dcd8e6e6b
commit
fa9e2c6237
@ -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;
|
||||
|
@ -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();
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.8 KiB |
@ -31,3 +31,10 @@
|
||||
How are \
|
||||
you?
|
||||
]
|
||||
|
||||
---
|
||||
#box(fill: aqua)[
|
||||
#place(top + left, dx: 50%, dy: 50%)[Hi]
|
||||
#v(30pt)
|
||||
#line(length: 50pt)
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user