Skip to content

Commit

Permalink
Update README.md to use macros
Browse files Browse the repository at this point in the history
  • Loading branch information
nixon-voxell authored Sep 23, 2024
1 parent 7747601 commit 932731d
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,18 @@ fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}

struct HelloWorld;

// Path to the Typst file that you created.
impl TypstPath for HelloWorld {
fn path() -> &'static str {
"typst/hello_world.typ"
}
}

// `main` function in Typst with their respective values.
// These values can be something else as long as they can be used to
// evaluate the respective input arguments needed for the function.
#[derive(Resource, Default)]
#[derive(TypstFunc, Resource, Default)]
#[typst_func(name = "main")] // name of function in the Typst file
struct MainFunc {
width: f64,
height: f64,
}

impl TypstFunc for MainFunc {
// Name of the function in the Typst file.
fn func_name(&self) -> &str {
"main"
}

// Create a ContextElem with the correct function arguments.
fn content(&self, func: foundations::Func) -> Content {
elem::context(func, |args| {
args.push(self.width);
args.push(self.height);
})
.pack()
}
}
// Path to the Typst file that you created.
#[derive(TypstPath)]
#[typst_path = "path/to/file.typ"]
struct HelloWorld;
```

## Interactions
Expand Down

0 comments on commit 932731d

Please sign in to comment.