Utilities

Flex Direction

The Flex Direction utility is key to controlling the direction in which children are laid out in a flex container. This utility helps define the primary axis of your layout, whether horizontal or vertical.

Utility Class
USS Properties
flex-row
flex-direction: row;
flex-row-reverse
flex-direction: row-reverse;
flex-col
flex-direction: column;
flex-col-reverse
flex-direction: column-reverse;

Using Flex Direction in UXML

Example: Horizontal Layout

Aligns children along a horizontal axis from left to right. The classes can also be used to reverse the order of children.

<ui:VisualElement class="flex-row">
    <!-- Children are laid out in a row -->
</ui:VisualElement>

<ui:VisualElement class="flex-row-reverse">
    <!-- Children are laid out in a row but in reverse order -->
</ui:VisualElement>

Example: Vertical Layout

Aligns children along a vertical axis from top to bottom. The classes can also be used to reverse the order of children.

<ui:VisualElement class="flex-col">
    <!-- Children are laid out in a column -->
</ui:VisualElement>

<ui:VisualElement class="flex-col-reverse">
    <!-- Children are laid out in a column but in reverse order -->
</ui:VisualElement>

Customize

Modifier Variations

Modifier Variations

You can customize which modifier variations of the Flex Direction utility are generated, such as pseudo-classes (e.g., hover, focus) and custom modifiers.

By default, no modifier variations are defined for the Flex Direction 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:

  1. Open the Theme Config Asset: Find the asset within your Unity project.
  2. Navigate to the 'Utilities' Section: Locate the Flex Direction utility.
  3. 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

Class Tags and Properties

The Flex Direction 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 Flex Direction utility:

  • flex : flex-direction

To customize these tags and properties, you can edit the Tag Property Map field for the Flex Direction 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 Flex Direction 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:

  1. Open the Theme Config Asset: Locate the asset within your Unity project.
  2. Navigate to the 'Utilities' Section: Find the Flex Direction utility.
  3. 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 Flex Direction 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.

Previous
Flex Basis