diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-02-12 21:14:21 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-02-12 21:14:21 +0100 |
| commit | d99359dede8f366fc16d38c6166b97a0f56fe0cb (patch) | |
| tree | 862ae2d48efb782f8061964302b4719b57f44618 /library | |
| parent | d689d706eaf3079877406e71b0d642623c9eb230 (diff) | |
Add `baseline` argument to `box`
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/layout/container.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index 7d733a87..09cfac8d 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -47,6 +47,8 @@ pub struct BoxNode { pub width: Smart<Rel<Length>>, /// The box's height. pub height: Smart<Rel<Length>>, + /// The box's baseline shift. + pub baseline: Rel<Length>, } #[node] @@ -55,7 +57,8 @@ impl BoxNode { let body = args.eat::<Content>()?.unwrap_or_default(); let width = args.named("width")?.unwrap_or_default(); let height = args.named("height")?.unwrap_or_default(); - Ok(Self { body, width, height }.pack()) + let baseline = args.named("baseline")?.unwrap_or_default(); + Ok(Self { body, width, height, baseline }.pack()) } fn field(&self, name: &str) -> Option<Value> { @@ -86,7 +89,15 @@ impl Layout for BoxNode { let is_auto = sizing.as_ref().map(Smart::is_auto); let expand = regions.expand | !is_auto; let pod = Regions::one(size, expand); - self.body.layout(vt, styles, pod) + let mut frame = self.body.layout(vt, styles, pod)?.into_frame(); + + // Apply baseline shift. + let shift = self.baseline.resolve(styles).relative_to(frame.height()); + if !shift.is_zero() { + frame.set_baseline(frame.baseline() - shift); + } + + Ok(Fragment::frame(frame)) } } |
