Layer behavior
Layer behaviors make shapes react when the size of the canvas changes. A button background can stretch to fill the width, an icon can stay pinned to the right edge, and a label can stay centered. They’re especially handy when building components.
To set a behavior, select one or more shapes or vector layers, then choose an option from Layer › Set Behavior. The same submenu is available by right clicking on the canvas. The pin behaviors have shortcuts — ⌃⇧←, ⌃⇧→, ⌃⇧↑, and ⌃⇧↓ — and Full Width and Height is ⌃⇧F. If a vector layer is selected, the behavior is applied to every shape inside it. Behaviors apply to rectangles, superellipses, polygons, stars, paths, and text.
There’s nothing magic about behaviors. Each one writes expressions into the shape’s position and size, using the built-in w and h constants, which return the current canvas width and height. That means you can see exactly what a behavior does by looking at the shape’s properties, and edit the expressions afterwards if you need something a little different.
The examples below assume a document that’s 1000px wide, containing a rectangle that’s 100px wide.
Pinning #
Pin Left and Pin Top keep the shape a fixed distance from the left or top edge. Since that’s how positions work anyway, these options replace any expressions in the shape’s horizontal or vertical position and size with plain numbers. They’re a quick way to remove other behaviors.
Pin Right and Pin Bottom keep the shape a fixed distance from the right or bottom edge. If our rectangle is 50px from the right edge (at an X position of 850), Pin Right sets the X position to :=w - 150. When the canvas gets wider, the rectangle moves right. The width stays fixed.
Centering #
Center Horizontally and Center Vertically keep the shape centered on the canvas. For our rectangle, Center Horizontally sets the X position to :=(w - 100) / 2.
Centering can land shapes on half pixels, which can make edges blurry. Center Horizontally (Rounded) and Center Vertically (Rounded) round the result to whole pixels, using :=round((w - 100) / 2).
Full width and full height #
Full Width sets the shape’s X position to 0 and its width to :=w, so it always spans the entire canvas. Full Height does the same vertically, using :=h. Full Width and Height does both, which is perfect for backgrounds.
Expand with width and height #
Expand with Width keeps the shape’s left and right margins the same, and stretches the shape as the canvas width changes. If our rectangle sits 50px in from both edges and is 900px wide, Expand with Width keeps the X position at 50 and sets the width to :=w - 100. Expand with Height does the same vertically, using h.
Behaviors and components #
Behaviors are handy when building components. If you change the canvas size of a component document, the shapes inside will pin, center, and stretch to suit the new size, rather than needing to be moved by hand. It makes it much quicker to create a set of similar components at different sizes.
Behaviors also work when a component layer is resized in another document. If the component layer’s Fitting option is Native (the default), w and h inside the component return the size of the component layer, so the shapes inside pin, center, and stretch as the layer is resized. With Fill, Contain, or Cover, w and h stay at the component document’s own canvas size, and the component is scaled instead.
Further reading: Expressions, constants, and components