Skip to main content

on-layer

on-layer() 

Places elements on a specific layer.

A layer determines the position of an element in the draw queue. A lower layer is drawn before a higher layer.

Layers can be used to draw behind or in front of other elements, even if the other elements were created before or after. An example would be drawing a background behind a text, but using the text's calculated bounding box for positioning the background.

// Draw something behind text
set-style(stroke: none)
content((0, 0), [This is an example.], name: "text")
on-layer(-1, {
circle("text.north-east", radius: .3, fill: red)
circle("text.south", radius: .4, fill: green)
circle("text.north-west", radius: .2, fill: blue)
})

layer:

โ€‹

The layer to place the elements on. Elements placed without on-layer are always placed on layer 0.

Elements to draw on the layer specified. A function that accepts ctx and returns elements is also accepted.