Changes

Jump to navigation Jump to search
2,264 bytes added ,  17:51, 19 August 2021
layers in fitting pages
< [[Layout]] | [[Columns]] | [[Overlays]] | [[Logos]] | [[Collectors]] >__TOC__
'''Layers''' are ConTeXt's mechanism for absolute positioning of elements and other advanced techniques like switching elements on and off. There’s still '''no manual about them'''.
There's still no manual about them. ==My first Layer==
Define a layer that takes the whole page
\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}}.
Now you can test the whole thing:
==Placement==
There are several possibilities for defining the placement of layer content:
Similarly you can define your own presets.
===Understanding "location" and "corner"===
The layer is divided into a 2x2 matrix of squares, where 'x' is the center.
Again you have nine different corners to choose from.
==== Example: An example to make this clear ====
Specifications '<code>corner={top,right},location={bottom,right}' </code> will place content in the area L (outside the original layer).
Think about the 'corner' c as a magnetic grid point, where the content snaps to.
The 'location' defines, from which direction we approach the point c.
* L = location (area)
o---o---o | | |
----o---c---o
| | | L |
----x---o---d
| | |
---------
==== ExampleAn example: placing a logo to the top right corner of the page ====
<context source=yes text="Givesgives:">
\definelayer
[Logo]
</context>
=Often it makes sense to use a preset (e.g. "lefttop") and move the contents with "hoffset" and "voffset" (positive values move into the page, negative values move into the outer borders). =State==
The available options for the "state" of a layer are:
* continue: layer appears on all pages except the first
=Layers on top= Usually, layers are in the background of your page (or text area). But sometimes you need your layer content on top of the regular content. Then you must set the foreground as one of the backgrounds like this: <texcode>\setupbackgrounds[page][background={mybacklayer,foreground,myfrontlayer}]</texcode> The order of backgrounds from left to right is from bottom to top. =Line breaking and fixed size==
You may experience cases where the defined size of your layer is ignored and you can’t get linebreaking or multiple lines at all.
This is due to <{{cmd>|setlayer</cmd> }} using <{{cmd>|hbox</cmd> }} internally. You can work around the problem using <{{cmd>|setlayerframed</cmd>}}:
<context source=yes>
==Place labels on pictures==
Layers can be used to put labels on pictures, alternative ways can be found in the [[manual:details.pdf| Details]] manual
</context>
==Use dynamic content==
The content of layer is fixed after your set it and will appear in the same way on each page.
This is not always what you desire like in the example above, where on each page the current page number should be shown and not the number from the first page.
To recalculate the content on each new page you have to enclose the <{{cmd>|setlayer</cmd> }} settings within <{{cmd>|startsetups</cmd> }} ... <{{cmd>|stopsetups</cmd> }} and
write <code>\setupbackgrounds[page][setups=setupname,background=layername]</code> in your document.
</texcode>
[[Setups]], by design, ignore the spaces inside them, so use {{cmd|space}}, {{cmd|crlf}}, {{cmd|par}}, etc., to request spaces, or use {{cmd|startrawsetups}}.
 
<texcode>
\definelayer
[pagenumber]
[width=\paperwidth,
height=\paperheight,
preset=middle]
 
\startsetups layer
 
\setlayerframed[pagenumber][align=middle]{Page Number: \par \pagenumber}
 
\stopsetups
 
\setupbackgrounds[page][setups=layer,background=pagenumber]
 
\starttext
\dorecurse{4}{\page[empty]} % You get "Page 1, Page 2" etc.
\stoptext
</texcode>
Another solution for dynamic content was given by Wolfgang on the mailing list on February 21, 2012. He writes: ''Here is a slightly different version which is better when you need more dynamic layers.''
<texcode>
</texcode>
== Layers and the delayed font mechanism == '''TL;DR: Setup your fonts before your layers.'''
Until some years ago the Latin Modern font was always automatically
a font needs to be set up beforehand.
== See Also =Layers in fitting pages =
Fitting pages have no fixed dimensions, but they are taken from their content. Layers require dimensions to be placed on the page.
 
Hans provided two alternative methods to do it:
 
<texcode>
\starttext
 
\definelayer[hi]
 
\startTEXpage[background=hi]
\setbox\scratchbox\hbox\framed
[frame=off,offset=none,align=middle]
{\input{tufte}}%
\setuplayer
[hi]
[width=\wd\scratchbox,height=\htdp\scratchbox]
\setlayer
[hi][preset=middle]
{\color[green]{there}}
\box\scratchbox
\stopTEXpage
 
\defineoverlay[hi]
 
\startTEXpage[background=hi]
\defineoverlay
[hi]
[{\framed [frame=off, offset=overlay, width=\overlaywidth, height=\overlayheight]
{\color[red]{there}}}]
\framed
[frame=off,offset=none,align=middle,background=hi]
{\input{tufte}}%
\stopTEXpage
 
\stoptext
</texcode>
 
= See Also =
 
* An example, [[Alternating backgrounds and repeating layers]] like Watermarks (2007)
* Some applications in the [[manual:details.pdf|Details]] manual
* [[Sample documents]]: [[BusinessCard]] and [[Letter style]]
* Example of [[Alternating backgrounds and repeating layers]] and [[Draft Watermark]]
* [http://www.ntg.nl/pipermail/ntg-context/2013/070935.html Layer vs. overlay] by Wolfgang
* {{cmd|setupbackgrounds}}
* {{cmd|definelayer}}, {{cmd|setuplayer}}
* {{cmd|setlayer}}, {{cmd|setlayerframed}}
{{todo|We need a lot of documentation and samples for this complicated subject.}}
 [[Category:Graphics]] [[Category:Layers]] [[Category:Layout]] [[Category:Basics]]
139

edits

Navigation menu