Utilities

Flex Shrink

The Flex Shrink utility is crucial for managing the relative shrinkage of flex items within a flex container. It defines how an item adjusts its size when there isn't enough space in the container.

Utility Class
USS Properties
flex-shrink-0
flex-shrink: 0;
flex-shrink
flex-shrink: 1;

Using Flex Shrink in UXML

Fixed Size Flex Item

This prevents the flex item from shrinking, ensuring it retains its original size even in space-constrained conditions.

<ui:VisualElement class="flex-shrink-0">
    <!-- This item won't shrink in size -->
</ui:VisualElement>

Shrinkable Flex Item

This allows the flex item to shrink as needed, sharing the available space with other flex items in the container.

<ui:VisualElement class="flex-shrink">
    <!-- This item will shrink in size -->
</ui:VisualElement>

Customize

Modifier Variations

Modifier Variations

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

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

  • flex-shrink : flex-shrink

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