Class Spacer
A layout component that creates consistent spacing between elements.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Spacer : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
The Spacer component is a versatile layout utility that helps create whitespace and manage spacing between elements in your UI. It provides predefined spacing options and can also expand to fill available space, making it essential for creating consistent and responsive layouts.
Spacers are non-interactive elements (they ignore pointer events) and can be used both vertically and horizontally depending on the parent container's layout direction.
The Spacer component automatically handles its styling through USS classes, making it easy to maintain consistent spacing across your application.
Examples
Basic usage in a horizontal layout. Creating equal spacing between buttons in a horizontal layout.
<Box style="flex-direction: row;">
<Button text="Left" />
<Spacer spacing="M" />
<Button text="Center" />
<Spacer spacing="M" />
<Button text="Right" />
</Box>
Using Spacer to push elements apart. Using an expanding spacer to push elements to opposite ends of a container.
<Box style="flex-direction: row;">
<Button text="Left-aligned" />
<Spacer spacing="Expand" />
<Button text="Right-aligned" />
</Box>
Vertical spacing in a column layout. Creating different spaces between form elements in a vertical layout.
<Box style="flex-direction: column;">
<Label text="Header" />
<Spacer spacing="S" />
<TextField />
<Spacer spacing="L" />
<Button text="Submit" />
</Box>
Constructors
Spacer()
Main constructor.
Declaration
public Spacer()
Fields
spacingUssClassName
The spacer's spacing USS class name.
Declaration
public const string spacingUssClassName = "appui-spacer--spacing-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The spacer's main USS class name.
Declaration
public const string ussClassName = "appui-spacer"
Field Value
| Type | Description |
|---|---|
| string |
Properties
spacing
The spacer's spacing.
Declaration
[CreateProperty]
[UxmlAttribute]
public SpacerSpacing spacing { get; set; }
Property Value
| Type | Description |
|---|---|
| SpacerSpacing |
Methods
GetSpacingUssClassName(SpacerSpacing)
Declaration
public static string GetSpacingUssClassName(SpacerSpacing enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| SpacerSpacing | enumValue |
Returns
| Type | Description |
|---|---|
| string |