From d99359dede8f366fc16d38c6166b97a0f56fe0cb Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 12 Feb 2023 21:14:21 +0100 Subject: Add `baseline` argument to `box` --- library/src/layout/container.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'library/src') 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>, /// The box's height. pub height: Smart>, + /// The box's baseline shift. + pub baseline: Rel, } #[node] @@ -55,7 +57,8 @@ impl BoxNode { let body = args.eat::()?.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 { @@ -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)) } } -- cgit v1.2.3