mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
39 lines
1.0 KiB
Rust
39 lines
1.0 KiB
Rust
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.require(ctx, "spacing");
|
|
Value::template(name, move |ctx| {
|
|
if let Some(linear) = spacing {
|
|
let amount = linear.resolve(ctx.state.font.resolve_size());
|
|
ctx.push_spacing(axis, amount, 0);
|
|
}
|
|
})
|
|
}
|