summaryrefslogtreecommitdiff
path: root/src/library/placed.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/placed.rs
parent738ff7e1f573bef678932b313be9969a17af8d22 (diff)
parent438255519e88bb790480306b9a9b452aaf054519 (diff)
Merge pull request #51 from typst/set-rules
Set rules
Diffstat (limited to 'src/library/placed.rs')
-rw-r--r--src/library/placed.rs26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/library/placed.rs b/src/library/placed.rs
index 722e0035..589a299b 100644
--- a/src/library/placed.rs
+++ b/src/library/placed.rs
@@ -6,27 +6,22 @@ pub fn place(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
let aligns = args.find().unwrap_or(Spec::new(Some(Align::Left), None));
let tx = args.named("dx")?.unwrap_or_default();
let ty = args.named("dy")?.unwrap_or_default();
- let body: Template = args.expect("body")?;
- Ok(Value::Template(Template::from_block(move |style| {
- PlacedNode {
- child: body.pack(style).moved(Point::new(tx, ty)).aligned(aligns),
- }
- })))
+ let body: Node = args.expect("body")?;
+ Ok(Value::block(PlacedNode(
+ body.into_block().moved(Point::new(tx, ty)).aligned(aligns),
+ )))
}
/// A node that places its child absolutely.
#[derive(Debug, Hash)]
-pub struct PlacedNode {
- /// The node to be placed.
- pub child: PackedNode,
-}
+pub struct PlacedNode(pub PackedNode);
impl PlacedNode {
/// Whether this node wants to be placed relative to its its parent's base
/// origin. instead of relative to the parent's current flow/cursor
/// position.
pub fn out_of_flow(&self) -> bool {
- self.child
+ self.0
.downcast::<AlignNode>()
.map_or(false, |node| node.aligns.y.is_some())
}
@@ -48,7 +43,7 @@ impl Layout for PlacedNode {
Regions::one(regions.base, regions.base, expand)
};
- let mut frames = self.child.layout(ctx, &pod);
+ let mut frames = self.0.layout(ctx, &pod);
let Constrained { item: frame, cts } = &mut frames[0];
// If expansion is off, zero all sizes so that we don't take up any
@@ -56,13 +51,6 @@ impl Layout for PlacedNode {
let target = regions.expand.select(regions.current, Size::zero());
Rc::make_mut(frame).resize(target, Align::LEFT_TOP);
- // Place relative to parent's base origin by offsetting our elements by
- // the negative cursor position.
- if out_of_flow {
- let offset = (regions.current - regions.base).to_point();
- Rc::make_mut(frame).translate(offset);
- }
-
// Set base constraint because our pod size is base and exact
// constraints if we needed to expand or offset.
*cts = Constraints::new(regions.expand);