summaryrefslogtreecommitdiff
path: root/src/library/shape.rs
diff options
context:
space:
mode:
authorMartin <mhaug@live.de>2021-12-22 20:37:34 +0100
committerGitHub <noreply@github.com>2021-12-22 20:37:34 +0100
commitf6c7a8292dc1ab0560408fca9d74505e9d7cf13a (patch)
treebadd3076f6146cec34c55764600df5124c408521 /src/library/shape.rs
parent738ff7e1f573bef678932b313be9969a17af8d22 (diff)
parent438255519e88bb790480306b9a9b452aaf054519 (diff)
Merge pull request #51 from typst/set-rules
Set rules
Diffstat (limited to 'src/library/shape.rs')
-rw-r--r--src/library/shape.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/library/shape.rs b/src/library/shape.rs
index 61c0d6e3..a9c9b333 100644
--- a/src/library/shape.rs
+++ b/src/library/shape.rs
@@ -1,6 +1,7 @@
use std::f64::consts::SQRT_2;
use super::prelude::*;
+use super::LinkNode;
/// `rect`: A rectangle with optional content.
pub fn rect(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
@@ -76,20 +77,15 @@ fn shape_impl(
}
// The shape's contents.
- let body = args.find::<Template>();
-
- Ok(Value::Template(Template::from_inline(move |style| {
- ShapeNode {
- kind,
- fill,
- stroke,
- child: body
- .as_ref()
- .map(|body| body.pack(style).padded(Sides::splat(padding))),
- }
- .pack()
- .sized(Spec::new(width, height))
- })))
+ let child = args
+ .find()
+ .map(|body: Node| body.into_block().padded(Sides::splat(padding)));
+
+ Ok(Value::inline(
+ ShapeNode { kind, fill, stroke, child }
+ .pack()
+ .sized(Spec::new(width, height)),
+ ))
}
/// Places its child into a sizable and fillable shape.
@@ -154,9 +150,10 @@ impl Layout for ShapeNode {
frames = vec![Frame::new(size).constrain(Constraints::tight(regions))];
}
+ let frame = Rc::make_mut(&mut frames[0].item);
+
// Add fill and/or stroke.
if self.fill.is_some() || self.stroke.is_some() {
- let frame = Rc::make_mut(&mut frames[0].item);
let geometry = match self.kind {
ShapeKind::Square | ShapeKind::Rect => Geometry::Rect(frame.size),
ShapeKind::Circle | ShapeKind::Ellipse => Geometry::Ellipse(frame.size),
@@ -171,6 +168,11 @@ impl Layout for ShapeNode {
frame.prepend(Point::zero(), Element::Shape(shape));
}
+ // Apply link if it exists.
+ if let Some(url) = ctx.styles.get_ref(LinkNode::URL) {
+ frame.link(url);
+ }
+
frames
}
}