Utilities
Translate
The Translate
utility enables you to reposition elements within their layout without altering their position in the document flow. This is particularly useful for subtle adjustments, animations, or enhancing the dynamic interactivity of your UI.
Utility Class | USS Properties |
---|---|
translate-x-0 | --zb-translate-x: 0px; |
translate-x-1 | --zb-translate-x: 4px; |
translate-x-2 | --zb-translate-x: 8px; |
translate-x-3 | --zb-translate-x: 12px; |
translate-x-4 | --zb-translate-x: 16px; |
translate-x-5 | --zb-translate-x: 20px; |
translate-x-6 | --zb-translate-x: 24px; |
translate-x-7 | --zb-translate-x: 28px; |
translate-x-8 | --zb-translate-x: 32px; |
translate-x-9 | --zb-translate-x: 36px; |
translate-x-10 | --zb-translate-x: 40px; |
translate-x-11 | --zb-translate-x: 44px; |
translate-x-12 | --zb-translate-x: 48px; |
translate-x-14 | --zb-translate-x: 56px; |
translate-x-16 | --zb-translate-x: 64px; |
translate-x-20 | --zb-translate-x: 80px; |
translate-x-24 | --zb-translate-x: 96px; |
translate-x-28 | --zb-translate-x: 112px; |
translate-x-32 | --zb-translate-x: 128px; |
translate-x-36 | --zb-translate-x: 144px; |
translate-x-40 | --zb-translate-x: 160px; |
translate-x-44 | --zb-translate-x: 176px; |
translate-x-48 | --zb-translate-x: 192px; |
translate-x-52 | --zb-translate-x: 208px; |
translate-x-56 | --zb-translate-x: 224px; |
translate-x-60 | --zb-translate-x: 240px; |
translate-x-64 | --zb-translate-x: 256px; |
translate-x-72 | --zb-translate-x: 288px; |
translate-x-80 | --zb-translate-x: 320px; |
translate-x-96 | --zb-translate-x: 384px; |
translate-x-px | --zb-translate-x: 1px; |
translate-x-0point5 | --zb-translate-x: 2px; |
translate-x-1point5 | --zb-translate-x: 6px; |
translate-x-2point5 | --zb-translate-x: 10px; |
translate-x-3point5 | --zb-translate-x: 14px; |
translate-x-minus-0 | --zb-translate-x: 0px; |
translate-x-minus-1 | --zb-translate-x: -4px; |
translate-x-minus-2 | --zb-translate-x: -8px; |
translate-x-minus-3 | --zb-translate-x: -12px; |
translate-x-minus-4 | --zb-translate-x: -16px; |
translate-x-minus-5 | --zb-translate-x: -20px; |
translate-x-minus-6 | --zb-translate-x: -24px; |
translate-x-minus-7 | --zb-translate-x: -28px; |
translate-x-minus-8 | --zb-translate-x: -32px; |
translate-x-minus-9 | --zb-translate-x: -36px; |
translate-x-minus-10 | --zb-translate-x: -40px; |
translate-x-minus-11 | --zb-translate-x: -44px; |
translate-x-minus-12 | --zb-translate-x: -48px; |
translate-x-minus-14 | --zb-translate-x: -56px; |
translate-x-minus-16 | --zb-translate-x: -64px; |
translate-x-minus-20 | --zb-translate-x: -80px; |
translate-x-minus-24 | --zb-translate-x: -96px; |
translate-x-minus-28 | --zb-translate-x: -112px; |
translate-x-minus-32 | --zb-translate-x: -128px; |
translate-x-minus-36 | --zb-translate-x: -144px; |
translate-x-minus-40 | --zb-translate-x: -160px; |
translate-x-minus-44 | --zb-translate-x: -176px; |
translate-x-minus-48 | --zb-translate-x: -192px; |
translate-x-minus-52 | --zb-translate-x: -208px; |
translate-x-minus-56 | --zb-translate-x: -224px; |
translate-x-minus-60 | --zb-translate-x: -240px; |
translate-x-minus-64 | --zb-translate-x: -256px; |
translate-x-minus-72 | --zb-translate-x: -288px; |
translate-x-minus-80 | --zb-translate-x: -320px; |
translate-x-minus-96 | --zb-translate-x: -384px; |
translate-x-minus-px | --zb-translate-x: -1px; |
translate-x-minus-0point5 | --zb-translate-x: -2px; |
translate-x-minus-1point5 | --zb-translate-x: -6px; |
translate-x-minus-2point5 | --zb-translate-x: -10px; |
translate-x-minus-3point5 | --zb-translate-x: -14px; |
translate-x-1of2 | --zb-translate-x: 50%; |
translate-x-1of3 | --zb-translate-x: 33.333333%; |
translate-x-2of3 | --zb-translate-x: 66.666667%; |
translate-x-1of4 | --zb-translate-x: 25%; |
translate-x-2of4 | --zb-translate-x: 50%; |
translate-x-3of4 | --zb-translate-x: 75%; |
translate-x-full | --zb-translate-x: 100%; |
translate-x-minus-1of2 | --zb-translate-x: -50%; |
translate-x-minus-1of3 | --zb-translate-x: -33.333333%; |
translate-x-minus-2of3 | --zb-translate-x: -66.666667%; |
translate-x-minus-1of4 | --zb-translate-x: -25%; |
translate-x-minus-2of4 | --zb-translate-x: -50%; |
translate-x-minus-3of4 | --zb-translate-x: -75%; |
translate-x-minus-full | --zb-translate-x: -100%; |
translate-y-0 | --zb-translate-y: 0px; |
translate-y-1 | --zb-translate-y: 4px; |
translate-y-2 | --zb-translate-y: 8px; |
translate-y-3 | --zb-translate-y: 12px; |
translate-y-4 | --zb-translate-y: 16px; |
translate-y-5 | --zb-translate-y: 20px; |
translate-y-6 | --zb-translate-y: 24px; |
translate-y-7 | --zb-translate-y: 28px; |
translate-y-8 | --zb-translate-y: 32px; |
translate-y-9 | --zb-translate-y: 36px; |
translate-y-10 | --zb-translate-y: 40px; |
translate-y-11 | --zb-translate-y: 44px; |
translate-y-12 | --zb-translate-y: 48px; |
translate-y-14 | --zb-translate-y: 56px; |
translate-y-16 | --zb-translate-y: 64px; |
translate-y-20 | --zb-translate-y: 80px; |
translate-y-24 | --zb-translate-y: 96px; |
translate-y-28 | --zb-translate-y: 112px; |
translate-y-32 | --zb-translate-y: 128px; |
translate-y-36 | --zb-translate-y: 144px; |
translate-y-40 | --zb-translate-y: 160px; |
translate-y-44 | --zb-translate-y: 176px; |
translate-y-48 | --zb-translate-y: 192px; |
translate-y-52 | --zb-translate-y: 208px; |
translate-y-56 | --zb-translate-y: 224px; |
translate-y-60 | --zb-translate-y: 240px; |
translate-y-64 | --zb-translate-y: 256px; |
translate-y-72 | --zb-translate-y: 288px; |
translate-y-80 | --zb-translate-y: 320px; |
translate-y-96 | --zb-translate-y: 384px; |
translate-y-px | --zb-translate-y: 1px; |
translate-y-0point5 | --zb-translate-y: 2px; |
translate-y-1point5 | --zb-translate-y: 6px; |
translate-y-2point5 | --zb-translate-y: 10px; |
translate-y-3point5 | --zb-translate-y: 14px; |
translate-y-minus-0 | --zb-translate-y: 0px; |
translate-y-minus-1 | --zb-translate-y: -4px; |
translate-y-minus-2 | --zb-translate-y: -8px; |
translate-y-minus-3 | --zb-translate-y: -12px; |
translate-y-minus-4 | --zb-translate-y: -16px; |
translate-y-minus-5 | --zb-translate-y: -20px; |
translate-y-minus-6 | --zb-translate-y: -24px; |
translate-y-minus-7 | --zb-translate-y: -28px; |
translate-y-minus-8 | --zb-translate-y: -32px; |
translate-y-minus-9 | --zb-translate-y: -36px; |
translate-y-minus-10 | --zb-translate-y: -40px; |
translate-y-minus-11 | --zb-translate-y: -44px; |
translate-y-minus-12 | --zb-translate-y: -48px; |
translate-y-minus-14 | --zb-translate-y: -56px; |
translate-y-minus-16 | --zb-translate-y: -64px; |
translate-y-minus-20 | --zb-translate-y: -80px; |
translate-y-minus-24 | --zb-translate-y: -96px; |
translate-y-minus-28 | --zb-translate-y: -112px; |
translate-y-minus-32 | --zb-translate-y: -128px; |
translate-y-minus-36 | --zb-translate-y: -144px; |
translate-y-minus-40 | --zb-translate-y: -160px; |
translate-y-minus-44 | --zb-translate-y: -176px; |
translate-y-minus-48 | --zb-translate-y: -192px; |
translate-y-minus-52 | --zb-translate-y: -208px; |
translate-y-minus-56 | --zb-translate-y: -224px; |
translate-y-minus-60 | --zb-translate-y: -240px; |
translate-y-minus-64 | --zb-translate-y: -256px; |
translate-y-minus-72 | --zb-translate-y: -288px; |
translate-y-minus-80 | --zb-translate-y: -320px; |
translate-y-minus-96 | --zb-translate-y: -384px; |
translate-y-minus-px | --zb-translate-y: -1px; |
translate-y-minus-0point5 | --zb-translate-y: -2px; |
translate-y-minus-1point5 | --zb-translate-y: -6px; |
translate-y-minus-2point5 | --zb-translate-y: -10px; |
translate-y-minus-3point5 | --zb-translate-y: -14px; |
translate-y-1of2 | --zb-translate-y: 50%; |
translate-y-1of3 | --zb-translate-y: 33.333333%; |
translate-y-2of3 | --zb-translate-y: 66.666667%; |
translate-y-1of4 | --zb-translate-y: 25%; |
translate-y-2of4 | --zb-translate-y: 50%; |
translate-y-3of4 | --zb-translate-y: 75%; |
translate-y-full | --zb-translate-y: 100%; |
translate-y-minus-1of2 | --zb-translate-y: -50%; |
translate-y-minus-1of3 | --zb-translate-y: -33.333333%; |
translate-y-minus-2of3 | --zb-translate-y: -66.666667%; |
translate-y-minus-1of4 | --zb-translate-y: -25%; |
translate-y-minus-2of4 | --zb-translate-y: -50%; |
translate-y-minus-3of4 | --zb-translate-y: -75%; |
translate-y-minus-full | --zb-translate-y: -100%; |
How Translation Works
Translation shifts an element along the x or y axis (or both), allowing for horizontal, vertical, or two-dimensional movement. This is achieved through the application of translate-x-
and translate-y-
classes, which set the translation distance.
Horizontal Translation
To move an element horizontally, use translate-x-{value}
classes, where {value}
specifies the distance. Positive values move the element to the right, while negative values move it to the left.
<ui:VisualElement class="transform translate-x-3">
<!-- Element moved 12px to the right -->
</ui:VisualElement>
Vertical Translation
For vertical movement, translate-y-{value}
classes are used similarly, with positive values moving the element downwards and negative values upwards.
<ui:VisualElement class="transform translate-y-2">
<!-- Element moved 8px down -->
</ui:VisualElement>
Combining Translations
You can combine both x and y translations to move an element diagonally. Ensure that the Transform utility is applied to activate these translations.
<ui:VisualElement class="transform translate-x-2 translate-y-3">
<!-- Element moved diagonally right and down -->
</ui:VisualElement>
Customize
Modifier Variations
You can customize which modifier variations of the Translate
utility are generated, such as pseudo-classes (e.g., hover
, focus
) and custom modifiers.
Translate
utility by default:- hover
- focus
By fine-tuning the utility variations, you maintain control over your stylesheet's size and complexity, ensuring that only necessary styles are included. To update these values:
- Open the Theme Config Asset: Find the asset within your Unity project.
- Navigate to the 'Utilities' Section: Locate the
Translate
utility. - Adjust Modifier Variations: Select which modifiers you want to be generated for the utility. Keep in mind that the order of the modifiers will affect the order and specificity of the generated USS classes.
Class Tags and Properties
The Translate
utility generates classes based on predefined tags and their associated USS properties. While we recommend keeping these defaults for consistency and ease of reference in our documentation, you have the option to customize them to suit your project's specific needs.
These values are prepended to the defined values in this format tag-{value}
. If a tag is empty, the generated class will simply be the value by itself.
Here are the default tags and the USS properties they set for the Translate
utility:
- translate-x : --zb-translate-x
- translate-y : --zb-translate-y
To customize these tags and properties, you can edit the Tag Property Map
field for the Translate
utility in the Theme Config asset. This allows you to define new tags or modify existing ones, thus tailoring the generated classes to your preferences.
Extending Core Fields
The Translate
utility uses values from the following fields from the Core
section of the Theme Config asset:
- Spacing
- NegativeSpacing
To customize or define these extended fields:
- Open the Theme Config Asset: Locate the asset within your Unity project.
- Navigate to the 'Utilities' Section: Find the
Translate
utility. - Customize Extend Fields: Modify or add fields in the
Extend Fields
array to change the core configuration values that are extended. You'll only be able to extend fields of the same type.
Disable Utility
The Translate
utility is enabled by default. You can disable it by unchecking the Enabled
option in the Theme Config asset. This will prevent the generation of the utility's styles.