Skip to content

How set-style()/canvas() sets "global" settings for all drawing functions? #157

Answered by fenjalien
Andrew15-5 asked this question in Q&A
Discussion options

You must be logged in to vote

To answer the question in the title, cetz has a dictionary called ctx ("context") which stores information like the current transform and styling. It gets passed around to pretty much everything that needs to draw. The styling itself is a dictionary kept in ctx.style which is modified by set-style. Note that ctx is not a global variable, it gets created within canvas and is passed as a parameter to each function.

So on to how you can access width, height and length without passing them to a function each time. You essentially want to modify ctx or ctx.style to add your parameters. The easiest way to do this is use set-style(width: ...) otherwise use a "before" or "style" key in the elemen…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by Andrew15-5
Comment options

You must be logged in to vote
5 replies
@johannes-wolf
Comment options

@Andrew15-5
Comment options

@Andrew15-5
Comment options

@fenjalien
Comment options

@Andrew15-5
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants