mirror of
https://github.com/typst/typst
synced 2025-06-28 08:12:53 +08:00
More heading configuration
This commit is contained in:
parent
c7f52ed048
commit
8013a0d0e6
@ -17,9 +17,16 @@ pub struct HeadingNode {
|
|||||||
impl HeadingNode {
|
impl HeadingNode {
|
||||||
/// The heading's font family.
|
/// The heading's font family.
|
||||||
pub const FAMILY: Smart<FontFamily> = Smart::Auto;
|
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
|
/// The fill color of text in the heading. Just the surrounding text color
|
||||||
/// if `auto`.
|
/// if `auto`.
|
||||||
pub const FILL: Smart<Paint> = Smart::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> {
|
fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Node> {
|
||||||
Ok(Node::block(Self {
|
Ok(Node::block(Self {
|
||||||
@ -30,7 +37,10 @@ impl HeadingNode {
|
|||||||
|
|
||||||
fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> {
|
fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> {
|
||||||
styles.set_opt(Self::FAMILY, args.named("family")?);
|
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::FILL, args.named("fill")?);
|
||||||
|
styles.set_opt(Self::ABOVE, args.named("above")?);
|
||||||
|
styles.set_opt(Self::BELOW, args.named("below")?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +56,10 @@ impl Layout for HeadingNode {
|
|||||||
|
|
||||||
let mut passed = StyleMap::new();
|
let mut passed = StyleMap::new();
|
||||||
passed.set(TextNode::STRONG, true);
|
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) {
|
if let Smart::Custom(family) = styles.get_ref(Self::FAMILY) {
|
||||||
passed.set(
|
passed.set(
|
||||||
@ -62,6 +75,18 @@ impl Layout for HeadingNode {
|
|||||||
passed.set(TextNode::FILL, fill);
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user