summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-18 12:50:28 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-18 12:50:28 +0100
commit5a59bb48216352d04f78c9a9392ca7cef280d7b2 (patch)
tree463ec7ef40078df17ea79e018caa3e8943bffc94 /src/library
parentb2e6a297893348a871fba8997017a9fc98d5674b (diff)
Page fill
Diffstat (limited to 'src/library')
-rw-r--r--src/library/page.rs26
-rw-r--r--src/library/shape.rs1
2 files changed, 24 insertions, 3 deletions
diff --git a/src/library/page.rs b/src/library/page.rs
index a5935002..6642de16 100644
--- a/src/library/page.rs
+++ b/src/library/page.rs
@@ -18,6 +18,7 @@ pub fn page(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
let right = args.named("right")?;
let bottom = args.named("bottom")?;
let flip = args.named("flip")?;
+ let fill = args.named("fill")?;
ctx.template.modify(move |style| {
let page = style.page_mut();
@@ -60,6 +61,10 @@ pub fn page(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
if flip.unwrap_or(false) {
std::mem::swap(&mut page.size.w, &mut page.size.h);
}
+
+ if let Some(fill) = fill {
+ page.fill = Some(Paint::Color(fill));
+ }
});
ctx.template.pagebreak(false);
@@ -77,10 +82,12 @@ pub fn pagebreak(_: &mut EvalContext, _: &mut Args) -> TypResult<Value> {
/// Layouts its children onto one or multiple pages.
#[derive(Debug, Hash)]
pub struct PageNode {
- /// The size of the page.
- pub size: Size,
/// The node that produces the actual pages.
pub child: PackedNode,
+ /// The size of the page.
+ pub size: Size,
+ /// The background fill.
+ pub fill: Option<Paint>,
}
impl PageNode {
@@ -90,6 +97,19 @@ impl PageNode {
// that axis.
let expand = self.size.to_spec().map(Length::is_finite);
let regions = Regions::repeat(self.size, self.size, expand);
- self.child.layout(ctx, &regions).into_iter().map(|c| c.item).collect()
+
+ // Layout the child.
+ let mut frames: Vec<_> =
+ self.child.layout(ctx, &regions).into_iter().map(|c| c.item).collect();
+
+ // Add background fill if requested.
+ if let Some(fill) = self.fill {
+ for frame in &mut frames {
+ let element = Element::Geometry(Geometry::Rect(frame.size), fill);
+ Rc::make_mut(frame).prepend(Point::zero(), element)
+ }
+ }
+
+ frames
}
}
diff --git a/src/library/shape.rs b/src/library/shape.rs
index 7c543958..d0df5f48 100644
--- a/src/library/shape.rs
+++ b/src/library/shape.rs
@@ -131,6 +131,7 @@ impl Layout for ShapeNode {
frames = node.layout(ctx, &pod);
}
+ // TODO: What if there are multiple or no frames?
// Extract the frame.
Rc::take(frames.into_iter().next().unwrap().item)
} else {