Constants
Constants are a way to replace a name with a number, boolean, unit, vector, color, or string across an entire document. They’re similar to constants in programming. This feature is sometimes called design tokens.
Constants live in the document properties tab. Choose View › Properties › Document, then click the add button at the top of the constants table to choose the type of constant to create: Number, Boolean, Unit, Vector, Color, or String. The options button next to it can sort constants by name, import and export constants, and delete the selected constants.
Constant names must start with a letter, and can only contain letters, numbers, and underscores. Dots can be used between the parts of a name, like padding.left.
Number constants #
Number constants are floating point values. They can be whole numbers, or fractional values. For example, it’s possible to create a number constant called favRadius with a value of 8. Typing favRadius into the corner radius of a rectangle would give the rectangle a corner radius of 8. Typing favRadius / 2 would give it a corner radius of 4. If := is included at the start of the expression, it will be kept, and changing the constant will update anywhere it has been used across the entire document (:=favRadius / 2).
Number constants can also have a minimum and maximum. If a minimum and maximum are provided, the constant is shown with a slider in the constants table, and its value is kept within that range. By setting a minimum and maximum value, and using an expression to round the values, it’s possible to have a tokenised corner radius as a slider that only allows multiples of 4. The expression :=round(myRadius / 4) * 4 will do just that.
The Steps value controls how many steps the slider has between the minimum and maximum, which can be used to constrain values to specific step sizes. A value of 0 steps means the slider will allow uninterrupted movement.
Please refer to the expressions page for more information on persistent expressions.
Boolean constants #
Boolean constants represent values that can either be true or false. True resolves to 1, false resolves to 0. Boolean constants can be used anywhere a number constant can be used. They can also be used in ternary operations.
Unit constants #
Units are floating point numbers that represent a scale factor of document pixels. For example, if a unit constant called gu was created and given a value of 8, then 1gu could be typed into an input field and result in a value of 8. If 2gu was typed into an input field, it would result in a value of 16.
This allows different units of measurement to be used on a per document basis. It means iOS points, Android dp, Android sp, and rems can be used in Skala documents.
There’s all kinds of interesting uses for this feature, like type scales, or mapping sizes to the physical world by setting up millimetres and inches. You can design in fathoms, if you want. Savvy?
Vector constants #
The vector type holds three floating point numbers. Individual values can be used in expressions by adding the index in square brackets — for a vector constant called offset, offset[0] is the first value, offset[1] is the second, and offset[2] is the third.
Color constants #
Color constants store a color, including its alpha, and can be used in materials by picking them from the color picker. Changing a color constant updates every material that uses it. Color constants also remember the format they were entered in, like hex or CSS, so they’re shown the same way next time.
Further reading: Color management
String constants #
The string type is a sequence of characters. String constants can only be used in text objects. String constant names need to be enclosed in braces: this is an example of some text with a {string_constant}. When editing text, constant names are shown. In other situations, constant values are shown.
Built-in constants #
Skala includes a few built-in number constants. w or width returns the current canvas width. h or height returns the current canvas height. These are helpful when building documents and components that adapt when the document size changes. Inside a component, w and h return the size of the component layer it’s placed in when the layer’s Fitting option is Native. For the other fitting options, they return the component document’s own size.
worwidth= The current canvas width.horheight= The current canvas height.pi= 3.1415926536.tau= 6.2831853072.e= Euler’s number, 2.7182818284.phi= The Golden Ratio, 1.6180339887.epsilon= A very small number, 0.0000000001.inf= Infinity.
Please note that Skala’s built-in constants can not be overridden. If you’d like to use w for something else, you’re out of luck. Sorry!
Importing from Pinwheel #
Colors, numbers, booleans, and strings can be imported from Pinwheel documents by clicking the options button at the top of the constants table and choosing Import Pinwheel. Each item becomes a constant, with any namespaced group names added to the start of the name. Items with dark mode or high contrast variants create extra constants ending in Dark, HighContrast, and HighContrastDark. As with JSON imports, constants with matching names are replaced.