Resolve place deltas relative to real container size

This commit is contained in:
Laurenz 2023-07-19 12:59:34 +02:00
parent 3dcd8e6e6b
commit fa9e2c6237
4 changed files with 18 additions and 9 deletions

View File

@ -134,6 +134,7 @@ enum FlowItem {
frame: Frame, frame: Frame,
x_align: Align, x_align: Align,
y_align: Smart<Option<Align>>, y_align: Smart<Option<Align>>,
delta: Axes<Rel<Abs>>,
float: bool, float: bool,
clearance: Abs, clearance: Abs,
}, },
@ -276,12 +277,13 @@ impl<'a> FlowLayouter<'a> {
let float = placed.float(styles); let float = placed.float(styles);
let clearance = placed.clearance(styles); let clearance = placed.clearance(styles);
let alignment = placed.alignment(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| { let x_align = alignment.map_or(Align::Center, |aligns| {
aligns.x.unwrap_or(GenAlign::Start).resolve(styles) aligns.x.unwrap_or(GenAlign::Start).resolve(styles)
}); });
let y_align = alignment.map(|align| align.y.resolve(styles)); let y_align = alignment.map(|align| align.y.resolve(styles));
let frame = placed.layout(vt, styles, self.regions)?.into_frame(); 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) self.layout_item(vt, item)
} }
@ -508,7 +510,7 @@ impl<'a> FlowLayouter<'a> {
offset += frame.height(); offset += frame.height();
output.push_frame(pos, frame); 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 x = x_align.position(size.x - frame.width());
let y = if float { let y = if float {
match y_align { 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) => { FlowItem::Footnote(frame) => {
let y = size.y - footnote_height + footnote_offset; let y = size.y - footnote_height + footnote_offset;

View File

@ -115,10 +115,7 @@ impl Layout for PlaceElem {
.at(self.span()); .at(self.span());
} }
let child = self let child = self.body().aligned(
.body()
.moved(Axes::new(self.dx(styles), self.dy(styles)))
.aligned(
alignment.unwrap_or_else(|| Axes::with_x(Some(Align::Center.into()))), alignment.unwrap_or_else(|| Axes::with_x(Some(Align::Center.into()))),
); );

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -31,3 +31,10 @@
How are \ How are \
you? you?
] ]
---
#box(fill: aqua)[
#place(top + left, dx: 50%, dy: 50%)[Hi]
#v(30pt)
#line(length: 50pt)
]