Skip to main content

set-ctx

set-ctx() 

An advanced element that allows you to modify the current canvas type:context. Note: The transformation matrix (transform) is rounded after calling the callback function and therefore might be not exactly the matrix specified. This is due to rounding errors and should not cause any problems.

You can store shared context data under a key in the ctx.shared-state dictionary. Note: the ctx.shared-state dictionary is not scoped by group or scope elements and can be used for canvas global state.

// Setting custom shared state
set-ctx(ctx => {
ctx.shared-state.my-state = (
key: 123
)
return ctx
})

// ...

// Access the context object
get-ctx(ctx => content((), [#repr(ctx.shared-state)]))

callback:

A function that accepts the type:context dictionary and only returns a new one.