diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index 7bb6a6e94..7d733a876 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -41,19 +41,21 @@ use crate::prelude::*; #[capable(Layout)] #[derive(Debug, Hash)] pub struct BoxNode { - /// How to size the content horizontally and vertically. - pub sizing: Axes>>, /// The content to be sized. pub body: Content, + /// The box's width. + pub width: Smart>, + /// The box's height. + pub height: Smart>, } #[node] impl BoxNode { fn construct(_: &Vm, args: &mut Args) -> SourceResult { - let width = args.named("width")?; - let height = args.named("height")?; let body = args.eat::()?.unwrap_or_default(); - Ok(Self { sizing: Axes::new(width, height), body }.pack()) + let width = args.named("width")?.unwrap_or_default(); + let height = args.named("height")?.unwrap_or_default(); + Ok(Self { body, width, height }.pack()) } fn field(&self, name: &str) -> Option { @@ -71,31 +73,20 @@ impl Layout for BoxNode { styles: StyleChain, regions: Regions, ) -> SourceResult { - // The "pod" is the region into which the child will be layouted. - let pod = { - // Resolve the sizing to a concrete size. - let size = self - .sizing - .resolve(styles) - .zip(regions.base()) - .map(|(s, b)| s.map(|v| v.relative_to(b))) - .unwrap_or(regions.size); + // Resolve the sizing to a concrete size. + let sizing = Axes::new(self.width, self.height); + let size = sizing + .resolve(styles) + .zip(regions.base()) + .map(|(s, b)| s.map(|v| v.relative_to(b))) + .unwrap_or(regions.size); - // Select the appropriate base and expansion for the child depending - // on whether it is automatically or relatively sized. - let is_auto = self.sizing.as_ref().map(Option::is_none); - let expand = regions.expand | !is_auto; - Regions::one(size, expand) - }; - - // Layout the child. - let mut frame = self.body.layout(vt, styles, pod)?.into_frame(); - - // Ensure frame size matches regions size if expansion is on. - let target = regions.expand.select(regions.size, frame.size()); - frame.resize(target, Align::LEFT_TOP); - - Ok(Fragment::frame(frame)) + // Select the appropriate base and expansion for the child depending + // on whether it is automatically or relatively sized. + 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) } } diff --git a/library/src/shared/ext.rs b/library/src/shared/ext.rs index bda4b6713..3e600b8de 100644 --- a/library/src/shared/ext.rs +++ b/library/src/shared/ext.rs @@ -16,9 +16,6 @@ pub trait ContentExt { /// Link the content to a destination. fn linked(self, dest: Destination) -> Self; - /// Force a size for this content. - fn boxed(self, sizing: Axes>>) -> Self; - /// Set alignments for this content. fn aligned(self, aligns: Axes>) -> Self; @@ -52,10 +49,6 @@ impl ContentExt for Content { self.styled(Meta::DATA, vec![Meta::Link(dest.clone())]) } - fn boxed(self, sizing: Axes>>) -> Self { - crate::layout::BoxNode { sizing, body: self }.pack() - } - fn aligned(self, aligns: Axes>) -> Self { self.styled(crate::layout::AlignNode::ALIGNS, aligns) }