summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-17 21:57:15 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-17 23:04:02 +0100
commitddb617390cf7150042726742749806eab6b3dd54 (patch)
treef102a8ad40e2127215c00c879c80e6432a3e26df /library/src
parentcabd0908e230e451bd9f1394390f8c5deb17182e (diff)
Simplify layout_inline's signature
Diffstat (limited to 'library/src')
-rw-r--r--library/src/graphics/hide.rs10
-rw-r--r--library/src/graphics/image.rs4
-rw-r--r--library/src/graphics/line.rs4
-rw-r--r--library/src/graphics/shape.rs16
-rw-r--r--library/src/layout/container.rs7
-rw-r--r--library/src/layout/mod.rs11
-rw-r--r--library/src/layout/transform.rs35
-rw-r--r--library/src/math/mod.rs4
-rw-r--r--library/src/text/par.rs6
9 files changed, 44 insertions, 53 deletions
diff --git a/library/src/graphics/hide.rs b/library/src/graphics/hide.rs
index 3affd809..0fdb8638 100644
--- a/library/src/graphics/hide.rs
+++ b/library/src/graphics/hide.rs
@@ -17,11 +17,9 @@ impl LayoutInline for HideNode {
world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
- let mut frames = self.0.layout_inline(world, regions, styles)?;
- for frame in &mut frames {
- frame.clear();
- }
- Ok(frames)
+ ) -> SourceResult<Frame> {
+ 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 6bf02265..5524e1c0 100644
--- a/library/src/graphics/image.rs
+++ b/library/src/graphics/image.rs
@@ -43,7 +43,7 @@ impl LayoutInline for ImageNode {
_: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
+ ) -> SourceResult<Frame> {
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 df427171..112274d2 100644
--- a/library/src/graphics/line.rs
+++ b/library/src/graphics/line.rs
@@ -42,7 +42,7 @@ impl LayoutInline for LineNode {
_: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
+ ) -> SourceResult<Frame> {
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 be67532a..e336c3a3 100644
--- a/library/src/graphics/shape.rs
+++ b/library/src/graphics/shape.rs
@@ -78,8 +78,8 @@ impl<const S: ShapeKind> LayoutInline for ShapeNode<S> {
world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
- let mut frames;
+ ) -> SourceResult<Frame> {
+ 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<const S: ShapeKind> LayoutInline for ShapeNode<S> {
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<const S: ShapeKind> LayoutInline for ShapeNode<S> {
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<const S: ShapeKind> LayoutInline for ShapeNode<S> {
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<const S: ShapeKind> LayoutInline for ShapeNode<S> {
frame.link(url.clone());
}
- Ok(frames)
+ Ok(frame)
}
}
diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs
index 20d80cba..eb899d54 100644
--- a/library/src/layout/container.rs
+++ b/library/src/layout/container.rs
@@ -26,7 +26,7 @@ impl LayoutInline for BoxNode {
world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
+ ) -> SourceResult<Frame> {
// 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 f79da71c..605da3b2 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<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>>;
+ ) -> SourceResult<Frame>;
}
impl LayoutInline for Content {
@@ -122,7 +122,10 @@ impl LayoutInline for Content {
world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
+ ) -> SourceResult<Frame> {
+ assert!(regions.backlog.is_empty());
+ assert!(regions.last.is_none());
+
if !self.has::<dyn Show>() || !styles.applicable(self) {
if let Some(node) = self.to::<dyn LayoutInline>() {
let barrier = StyleEntry::Barrier(self.id());
@@ -133,7 +136,7 @@ impl LayoutInline for Content {
if let Some(node) = self.to::<dyn LayoutBlock>() {
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 4e0b8ac2..c45aa165 100644
--- a/library/src/layout/transform.rs
+++ b/library/src/layout/transform.rs
@@ -30,16 +30,12 @@ impl LayoutInline for MoveNode {
world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
- let mut frames = self.child.layout_inline(world, regions, styles)?;
-
+ ) -> SourceResult<Frame> {
+ 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<const T: TransformKind> LayoutInline for TransformNode<T> {
world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
- let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON);
- let mut frames = self.child.layout_inline(world, regions, styles)?;
+ ) -> SourceResult<Frame> {
+ let mut frame = self.child.layout_inline(world, regions, styles)?;
- 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);
- }
+ let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON);
+ 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 bcf09c04..7772c0af 100644
--- a/library/src/math/mod.rs
+++ b/library/src/math/mod.rs
@@ -51,8 +51,8 @@ impl LayoutInline for MathNode {
world: Tracked<dyn World>,
_: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
- Ok(vec![layout_tex(&self.texify(), self.display, world, styles)?])
+ ) -> SourceResult<Frame> {
+ layout_tex(&self.texify(), self.display, world, styles)
}
}
diff --git a/library/src/text/par.rs b/library/src/text/par.rs
index df02bc3c..1d01071d 100644
--- a/library/src/text/par.rs
+++ b/library/src/text/par.rs
@@ -141,7 +141,7 @@ impl LayoutInline for RepeatNode {
world: Tracked<dyn World>,
regions: &Regions,
styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
+ ) -> SourceResult<Frame> {
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;