diff options
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)) } } |
