summaryrefslogtreecommitdiff
path: root/src/library/spacing.rs
blob: 654a18c4bdfd193bf8f5878e99ad5d76eadeab13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use super::*;

/// `h`: Horizontal spacing.
///
/// # Positional parameters
/// - Amount of spacing: of type `linear` relative to current font size.
///
/// # Return value
/// A template that inserts horizontal spacing.
pub fn h(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
    spacing_impl("h", ctx, args, GenAxis::Cross)
}

/// `v`: Vertical spacing.
///
/// # Positional parameters
/// - Amount of spacing: of type `linear` relative to current font size.
///
/// # Return value
/// A template that inserts vertical spacing.
pub fn v(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
    spacing_impl("v", ctx, args, GenAxis::Main)
}

fn spacing_impl(
    name: &str,
    ctx: &mut EvalContext,
    args: &mut FuncArgs,
    axis: GenAxis,
) -> Value {
    let spacing: Option<Linear> = args.eat_expect(ctx, "spacing");
    Value::template(name, move |ctx| {
        if let Some(linear) = spacing {
            // TODO: Should this really always be font-size relative?
            let amount = linear.resolve(ctx.state.font.size);
            ctx.push_spacing(axis, amount);
        }
    })
}