macro_rules! typst_func {
(
// The literal function name from the Typst scope,
// usually from the source file.
$str_name:literal,
// Attributes.
$( #[$attr:meta] )*
$vis:vis struct $struct_name:ident
// Lifetimes and generics.
$(< $( $generic:tt $( : $bound:tt $(+ $_bound:tt )* )? ),+ >)? {}$(,)?
// Positional args
$(
positional_args {
// Optional positional args.
$(
$( #[$positional_attr:meta] )*
$positional_vis:vis $positional_arg:ident: $positional_type:ty
),*$(,)?
}$(,)?
)?
// Named args.
$(
named_args {
$(
$( #[$named_attr:meta] )*
$named_vis:vis $named_arg:ident: $named_type:ty
),*$(,)?
}$(,)?
)?
) => { ... };
}Expand description
Helper macro for creating Typst function struct with
TypstFunc trait implementation.
§Example
use bevy::prelude::*;
use velyst::prelude::*;
typst_func!(
// The literal function name from the Typst scope,
// usually from the source file.
"button",
/// A button function from Typst.
#[derive(Component, Reflect)]
#[reflect(Component)]
struct ButtonFunc<T: TypstValue> {},
// Positional arguments, order matters here!
positional_args {
/// Label size.
size: f64,
custom_data: T,
/// Button label.
#[reflect(ignore)]
label: String,
},
// Named arguments, order doesn't really matters here.
named_args {
icon_index: u32,
#[reflect(ignore)]
icon_label: String,
},
);Arguments can be also omitted if there aren’t any:
use velyst::typst_func;
typst_func!("empty", struct EmptyFunc {});