summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/heading.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/library/heading.rs b/src/library/heading.rs
index d3beb4ee..4c7bcc7d 100644
--- a/src/library/heading.rs
+++ b/src/library/heading.rs
@@ -17,9 +17,16 @@ pub struct HeadingNode {
impl HeadingNode {
/// The heading's font family.
pub const FAMILY: Smart<FontFamily> = Smart::Auto;
+ /// The size of text in the heading. Just the surrounding text size if
+ /// `auto`.
+ pub const SIZE: Smart<Linear> = Smart::Auto;
/// The fill color of text in the heading. Just the surrounding text color
/// if `auto`.
pub const FILL: Smart<Paint> = Smart::Auto;
+ /// The extra padding above the heading.
+ pub const ABOVE: Length = Length::zero();
+ /// The extra padding below the heading.
+ pub const BELOW: Length = Length::zero();
fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Node> {
Ok(Node::block(Self {
@@ -30,7 +37,10 @@ impl HeadingNode {
fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> {
styles.set_opt(Self::FAMILY, args.named("family")?);
+ styles.set_opt(Self::SIZE, args.named("size")?);
styles.set_opt(Self::FILL, args.named("fill")?);
+ styles.set_opt(Self::ABOVE, args.named("above")?);
+ styles.set_opt(Self::BELOW, args.named("below")?);
Ok(())
}
}
@@ -46,7 +56,10 @@ impl Layout for HeadingNode {
let mut passed = StyleMap::new();
passed.set(TextNode::STRONG, true);
- passed.set(TextNode::SIZE, Relative::new(upscale).into());
+ passed.set(
+ TextNode::SIZE,
+ styles.get(Self::SIZE).unwrap_or(Relative::new(upscale).into()),
+ );
if let Smart::Custom(family) = styles.get_ref(Self::FAMILY) {
passed.set(
@@ -62,6 +75,18 @@ impl Layout for HeadingNode {
passed.set(TextNode::FILL, fill);
}
- self.child.layout(ctx, regions, passed.chain(&styles))
+ let mut frames = self.child.layout(ctx, regions, passed.chain(&styles));
+
+ let above = styles.get(Self::ABOVE);
+ let below = styles.get(Self::BELOW);
+
+ // FIXME: Constraints and region size.
+ for Constrained { item: frame, .. } in &mut frames {
+ let frame = Rc::make_mut(frame);
+ frame.size.y += above + below;
+ frame.translate(Point::with_y(above));
+ }
+
+ frames
}
}