diff --git a/library/src/graphics/hide.rs b/library/src/graphics/hide.rs index 3affd8099..0fdb86382 100644 --- a/library/src/graphics/hide.rs +++ b/library/src/graphics/hide.rs @@ -17,11 +17,9 @@ impl LayoutInline for HideNode { world: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { - let mut frames = self.0.layout_inline(world, regions, styles)?; - for frame in &mut frames { - frame.clear(); - } - Ok(frames) + ) -> SourceResult { + let mut frame = self.0.layout_inline(world, regions, styles)?; + frame.clear(); + Ok(frame) } } diff --git a/library/src/graphics/image.rs b/library/src/graphics/image.rs index 6bf02265f..5524e1c0f 100644 --- a/library/src/graphics/image.rs +++ b/library/src/graphics/image.rs @@ -43,7 +43,7 @@ impl LayoutInline for ImageNode { _: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { + ) -> SourceResult { let pxw = self.0.width() as f64; let pxh = self.0.height() as f64; let px_ratio = pxw / pxh; @@ -94,7 +94,7 @@ impl LayoutInline for ImageNode { frame.link(url.clone()); } - Ok(vec![frame]) + Ok(frame) } } diff --git a/library/src/graphics/line.rs b/library/src/graphics/line.rs index df4271717..112274d2d 100644 --- a/library/src/graphics/line.rs +++ b/library/src/graphics/line.rs @@ -42,7 +42,7 @@ impl LayoutInline for LineNode { _: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { + ) -> SourceResult { let stroke = styles.get(Self::STROKE).unwrap_or_default(); let origin = self @@ -63,6 +63,6 @@ impl LayoutInline for LineNode { let shape = Geometry::Line(delta.to_point()).stroked(stroke); frame.push(origin.to_point(), Element::Shape(shape)); - Ok(vec![frame]) + Ok(frame) } } diff --git a/library/src/graphics/shape.rs b/library/src/graphics/shape.rs index be67532ab..e336c3a31 100644 --- a/library/src/graphics/shape.rs +++ b/library/src/graphics/shape.rs @@ -78,8 +78,8 @@ impl LayoutInline for ShapeNode { world: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { - let mut frames; + ) -> SourceResult { + let mut frame; if let Some(child) = &self.0 { let mut inset = styles.get(Self::INSET); if is_round(S) { @@ -90,7 +90,7 @@ impl LayoutInline for ShapeNode { let child = child.clone().padded(inset.map(|side| side.map(Length::from))); let mut pod = Regions::one(regions.first, regions.base, regions.expand); - frames = child.layout_inline(world, &pod, styles)?; + frame = child.layout_inline(world, &pod, styles)?; // Relayout with full expansion into square region to make sure // the result is really a square or circle. @@ -99,14 +99,14 @@ impl LayoutInline for ShapeNode { let target = regions.expand.select(regions.first, Size::zero()); target.x.max(target.y) } else { - let size = frames[0].size(); + let size = frame.size(); let desired = size.x.max(size.y); desired.min(regions.first.x).min(regions.first.y) }; pod.first = Size::splat(length); pod.expand = Axes::splat(true); - frames = child.layout_inline(world, &pod, styles)?; + frame = child.layout_inline(world, &pod, styles)?; } } else { // The default size that a shape takes on if it has no child and @@ -125,11 +125,9 @@ impl LayoutInline for ShapeNode { size = regions.expand.select(regions.first, size); } - frames = vec![Frame::new(size)]; + frame = Frame::new(size); } - let frame = &mut frames[0]; - // Add fill and/or stroke. let fill = styles.get(Self::FILL); let stroke = match styles.get(Self::STROKE) { @@ -167,7 +165,7 @@ impl LayoutInline for ShapeNode { frame.link(url.clone()); } - Ok(frames) + Ok(frame) } } diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index 20d80cbac..eb899d547 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -26,7 +26,7 @@ impl LayoutInline for BoxNode { world: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { + ) -> SourceResult { // The "pod" is the region into which the child will be layouted. let pod = { // Resolve the sizing to a concrete size. @@ -47,14 +47,13 @@ impl LayoutInline for BoxNode { }; // Layout the child. - let mut frames = self.child.layout_inline(world, &pod, styles)?; + let mut frame = self.child.layout_inline(world, &pod, styles)?; // Ensure frame size matches regions size if expansion is on. - let frame = &mut frames[0]; let target = regions.expand.select(regions.first, frame.size()); frame.resize(target, Align::LEFT_TOP); - Ok(frames) + Ok(frame) } } diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index f79da71c9..605da3b2c 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -112,7 +112,7 @@ pub trait LayoutInline: 'static + Sync + Send { world: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult>; + ) -> SourceResult; } impl LayoutInline for Content { @@ -122,7 +122,10 @@ impl LayoutInline for Content { world: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { + ) -> SourceResult { + assert!(regions.backlog.is_empty()); + assert!(regions.last.is_none()); + if !self.has::() || !styles.applicable(self) { if let Some(node) = self.to::() { let barrier = StyleEntry::Barrier(self.id()); @@ -133,7 +136,7 @@ impl LayoutInline for Content { if let Some(node) = self.to::() { let barrier = StyleEntry::Barrier(self.id()); let styles = barrier.chain(&styles); - return node.layout_block(world, regions, styles); + return Ok(node.layout_block(world, regions, styles)?.remove(0)); } } @@ -141,7 +144,7 @@ impl LayoutInline for Content { let mut builder = Builder::new(world, &scratch, false); builder.accept(self, styles)?; let (flow, shared) = builder.into_flow(styles)?; - flow.layout_block(world, regions, shared) + Ok(flow.layout_block(world, regions, shared)?.remove(0)) } } diff --git a/library/src/layout/transform.rs b/library/src/layout/transform.rs index 4e0b8ac21..c45aa165a 100644 --- a/library/src/layout/transform.rs +++ b/library/src/layout/transform.rs @@ -30,16 +30,12 @@ impl LayoutInline for MoveNode { world: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { - let mut frames = self.child.layout_inline(world, regions, styles)?; - + ) -> SourceResult { + let mut frame = self.child.layout_inline(world, regions, styles)?; let delta = self.delta.resolve(styles); - for frame in &mut frames { - let delta = delta.zip(frame.size()).map(|(d, s)| d.relative_to(s)); - frame.translate(delta.to_point()); - } - - Ok(frames) + let delta = delta.zip(frame.size()).map(|(d, s)| d.relative_to(s)); + frame.translate(delta.to_point()); + Ok(frame) } } @@ -88,20 +84,17 @@ impl LayoutInline for TransformNode { world: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { + ) -> SourceResult { + let mut frame = self.child.layout_inline(world, regions, styles)?; + let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON); - let mut frames = self.child.layout_inline(world, regions, styles)?; + let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); + let transform = Transform::translate(x, y) + .pre_concat(self.transform) + .pre_concat(Transform::translate(-x, -y)); + frame.transform(transform); - for frame in &mut frames { - let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); - let transform = Transform::translate(x, y) - .pre_concat(self.transform) - .pre_concat(Transform::translate(-x, -y)); - - frame.transform(transform); - } - - Ok(frames) + Ok(frame) } } diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index bcf09c040..7772c0af8 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -51,8 +51,8 @@ impl LayoutInline for MathNode { world: Tracked, _: &Regions, styles: StyleChain, - ) -> SourceResult> { - Ok(vec![layout_tex(&self.texify(), self.display, world, styles)?]) + ) -> SourceResult { + layout_tex(&self.texify(), self.display, world, styles) } } diff --git a/library/src/text/par.rs b/library/src/text/par.rs index df02bc3cd..1d01071da 100644 --- a/library/src/text/par.rs +++ b/library/src/text/par.rs @@ -141,7 +141,7 @@ impl LayoutInline for RepeatNode { world: Tracked, regions: &Regions, styles: StyleChain, - ) -> SourceResult> { + ) -> SourceResult { self.0.layout_inline(world, regions, styles) } } @@ -526,7 +526,7 @@ fn prepare<'a>( } else { let size = Size::new(regions.first.x, regions.base.y); let pod = Regions::one(size, regions.base, Axes::splat(false)); - let mut frame = inline.layout_inline(world, &pod, styles)?.remove(0); + let mut frame = inline.layout_inline(world, &pod, styles)?; frame.translate(Point::with_y(styles.get(TextNode::BASELINE))); items.push(Item::Frame(frame)); } @@ -1151,7 +1151,7 @@ fn commit( let fill = Fr::one().share(fr, remaining); let size = Size::new(fill, regions.base.y); let pod = Regions::one(size, regions.base, Axes::new(false, false)); - let frame = repeat.layout_inline(world, &pod, *styles)?.remove(0); + let frame = repeat.layout_inline(world, &pod, *styles)?; let width = frame.width(); let count = (fill / width).floor(); let remaining = fill % width; diff --git a/src/model/items.rs b/src/model/items.rs index e9c23c264..40f32fc42 100644 --- a/src/model/items.rs +++ b/src/model/items.rs @@ -23,7 +23,7 @@ pub static LANG_ITEMS: OnceCell = OnceCell::new(); /// break incremental, but only when different sets of lang items are used in /// the same program. For this reason, if this function is called multiple /// times, the items must be the same. -pub fn set_lang_items(items: LangItems) { +pub(crate) fn set_lang_items(items: LangItems) { if LANG_ITEMS.set(items).is_err() { let first = hash128(LANG_ITEMS.get().unwrap()); let second = hash128(&items);