Changes

,  14:56, 5 June 2015
m
no edit summary
< [[Layout]] | [[Columns]] | [[Overlays]] | [[Logos]] | [[Collectors]] >
'''Layers''' are ConTeXt's mechanism for absolute positioning of elements and other advanced techniques like switching elements on and off.
There's There’s still no manual about them.
==My first Layer==
Define a layer that takes the whole page, but starts with an offset
<texcode>
\definelayer [mybg] % name of the layer [x=-3mm0mm, y=-3mm0mm, % bleed over the pagefrom upper left corner of paper width=\paperwidth, height=\paperheight]% let the layer cover the full paper
</texcode>
Now you can put something on in that layer:
<texcode>
\setlayer [mybg] % name of the layer [xhoffset=2cm1cm, yvoffset=5cm1cm] % placement (from upper left corner of the layer) {\framed[frame=on, width=3cm, height=2cm]{LAYER}} % the actual contents of the layer
</texcode>
Activate the layer as a background:
<texcode>
\setupbackgrounds [page] [background=mybg]
</texcode>
This command makes the contents of the layer appear only once after the background is activated. If you want to repeat the contents of the layer on each page, use the option <code>repeat=yes</code> in the {{cmd|definelayer}} command. Then the contents of the layer will be shown on every page. You can add to these contents by a new {{cmd|setlayer}}[mybg] command. To clear the accumulated contents use {{cmd|resetlayer}}[mybg]. To make the layer appear on each page, so that it can be populated with different content, set the option <code>state=repeat</code> in {{cmd|setupbackgrounds}}.
You could also typeset Now you can test the layer once using <cmd>placelayerwhole thing:</cmd> or <cmd>flushlayer</cmdcontext source=yes>\setuppapersize[A10][A9, but then landscape]\setuparranging[2UP] % two pages side by side\showframe % show entire pages \definelayer[mybg] % name of the location depends layer [x=0mm, y=0mm, % from upper left corner of paper width=\paperwidth, height=\paperheight, % let the layer cover the full paper ] \setupbackgrounds[page][background=mybg] \setlayer[mybg] % name of the layer [hoffset=0.2cm, voffset=0.2cm] % placement (from upper left corner of the text area! (Bug?layer) {\framed[frame=on, width=2cm, height=1cm]{LAYER}} % the actual contents of the layer \starttext \dorecurse{2}{\page[empty]} % for testing, to get 2 pages, 1st with layer, 2nd without \stoptext </context>
* switch off backgrounds: <code>\setupbackgrounds[page][background=]</code>
* add a background: <code>\setupbackgrounds[page][background={\currentvalue, mylayer}]</code>
==Placement==
There are several possibilities for defining the placement of layer content:
* x, y : offset from upper left corner of paper[=the current block; can sometimes be the text area instead of the page/paper!]
* hoffset, voffset : offset from upper left corner of layer
* corner : reference point, something like <code>{left, top}</code>
* preset : a named location, see below
There are some "presets" for paper egde edge placement:
<texcode>
% These four are defined by ConTeXt!
Similarly you can define your own presets.