Utilities
Transform Origin
The Transform Origin
utility specifies the point around which transformations such as rotation, scaling, and translation are applied to an element. This point is crucial for determining how the transformation affects the element's position and orientation.
Utility Class | USS Properties |
---|---|
origin-center | transform-origin: center center; |
origin-top | transform-origin: top; |
origin-top-right | transform-origin: top right; |
origin-right | transform-origin: right; |
origin-bottom-right | transform-origin: bottom right; |
origin-bottom | transform-origin: bottom; |
origin-bottom-left | transform-origin: bottom left; |
origin-left | transform-origin: left; |
origin-top-left | transform-origin: top left; |
Overview
Transformations in UI elements can dramatically affect the user experience by providing dynamic feedback, creating engaging animations, or simply adjusting the element's layout for better visual appeal. The transform origin is a pivotal aspect of this process, acting as the fulcrum around which all transformations rotate, scale, or move.
Applying Transform Origin
You can set the transform origin of an element using the following utility classes, which align the origin to different positions within the element's bounding box.
<ui:VisualElement class="origin-center rotate-45">
<!-- Element with transform origin at the center and rotated 45 degrees -->
</ui:VisualElement>
<ui:VisualElement class="origin-top-right scale-105">
<!-- Element with transform origin at the top right corner and scaled -->
</ui:VisualElement>
Customize
Modifier Variations
You can customize which modifier variations of the Transform Origin
utility are generated, such as pseudo-classes (e.g., hover
, focus
) and custom modifiers.
Transform Origin
utility.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
Transform Origin
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 Transform Origin
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 Transform Origin
utility:
- origin : transform-origin
To customize these tags and properties, you can edit the Tag Property Map
field for the Transform Origin
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 Transform Origin
utility does not extend any fields from the Core
section of the Theme Config asset. Before you try to extend any fields, we recommend checking Unity's documentation to verify which types of values are expected by the relevant USS properties.
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
Transform Origin
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 Transform Origin
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.