diff options
| author | Martin <mhaug@live.de> | 2022-01-01 12:56:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-01 12:56:03 +0100 |
| commit | 28fc2893e873d44aa31a64a87cb3e2e975977a70 (patch) | |
| tree | bad022650bb488492386e4fc079dde3807b89304 /src/library/heading.rs | |
| parent | 5d5d8a21cfc041ab08d30229f4ecb4cbb415cbc5 (diff) | |
| parent | 179a9f479831c4941253c0517fccdec3acd8f2ff (diff) | |
Merge pull request #53 from typst/style-chains
Diffstat (limited to 'src/library/heading.rs')
| -rw-r--r-- | src/library/heading.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/library/heading.rs b/src/library/heading.rs index f2ed3194..111472f4 100644 --- a/src/library/heading.rs +++ b/src/library/heading.rs @@ -32,7 +32,7 @@ impl Construct for HeadingNode { } impl Set for HeadingNode { - fn set(args: &mut Args, styles: &mut Styles) -> TypResult<()> { + fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> { styles.set_opt(Self::FAMILY, args.named("family")?); styles.set_opt(Self::FILL, args.named("fill")?); Ok(()) @@ -44,23 +44,28 @@ impl Layout for HeadingNode { &self, ctx: &mut LayoutContext, regions: &Regions, + styles: StyleChain, ) -> Vec<Constrained<Rc<Frame>>> { let upscale = (1.6 - 0.1 * self.level as f64).max(0.75); - ctx.styles.set(TextNode::STRONG, true); - ctx.styles.set(TextNode::SIZE, Relative::new(upscale).into()); - if let Smart::Custom(family) = ctx.styles.get_ref(Self::FAMILY) { - let list = std::iter::once(family) - .chain(ctx.styles.get_ref(TextNode::FAMILY_LIST)) - .cloned() - .collect(); - ctx.styles.set(TextNode::FAMILY_LIST, list); + let mut local = StyleMap::new(); + local.set(TextNode::STRONG, true); + local.set(TextNode::SIZE, Relative::new(upscale).into()); + + if let Smart::Custom(family) = styles.get_ref(Self::FAMILY) { + local.set( + TextNode::FAMILY_LIST, + std::iter::once(family) + .chain(styles.get_ref(TextNode::FAMILY_LIST)) + .cloned() + .collect(), + ); } - if let Smart::Custom(fill) = ctx.styles.get(Self::FILL) { - ctx.styles.set(TextNode::FILL, fill); + if let Smart::Custom(fill) = styles.get(Self::FILL) { + local.set(TextNode::FILL, fill); } - self.child.layout(ctx, regions) + self.child.layout(ctx, regions, local.chain(&styles)) } } |
