Class RectAnchorPresets
The anchor preset picker from Unity's RectTransform inspector: a 4×4 grid of anchor configurations.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class RectAnchorPresets : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
Columns run left / centre / right / stretch-horizontally, rows top / middle / bottom / stretch-vertically. Presentation only: choosing a preset raises picked with the anchors and the held modifiers, and the caller applies them to its own model. That split is deliberate — recomputing a RectTransform from new anchors is backend math, not UI.
Hold Shift while picking to also move the pivot, Alt to also move the position. Those are reported, not applied.
Anchors are normalised fractions of the parent, y-up, matching anchorMin and anchorMax.
Examples
Wiring the picker to a RectTransform.
var presets = new RectAnchorPresets
{
anchorMin = target.anchorMin,
anchorMax = target.anchorMax,
};
presets.picked += evt =>
{
target.anchorMin = evt.anchorMin;
target.anchorMax = evt.anchorMax;
if (evt.setPivot)
target.pivot = (evt.anchorMin + evt.anchorMax) * 0.5f;
};
In UXML.
<appui:RectAnchorPresets />
Constructors
RectAnchorPresets()
Default constructor.
Declaration
public RectAnchorPresets()
Fields
altHint
The hint explaining what Alt does. Exposed so a caller can localise it.
Declaration
public const string altHint = "Alt: Also set position"
Field Value
| Type | Description |
|---|---|
| string |
cellUssClassName
The styling class of one preset cell.
Declaration
public const string cellUssClassName = "appui-rect-anchor-presets__cell"
Field Value
| Type | Description |
|---|---|
| string |
columns
The grid's column spans: left, centre, right, stretch.
Declaration
public static readonly Vector2[] columns
Field Value
| Type | Description |
|---|---|
| Vector2[] |
gridUssClassName
The styling class of the 4×4 grid.
Declaration
public const string gridUssClassName = "appui-rect-anchor-presets__grid"
Field Value
| Type | Description |
|---|---|
| string |
hintUssClassName
The styling class of the modifier hints below the grid.
Declaration
public const string hintUssClassName = "appui-rect-anchor-presets__hint"
Field Value
| Type | Description |
|---|---|
| string |
rowUssClassName
The styling class of one row of the grid.
Declaration
public const string rowUssClassName = "appui-rect-anchor-presets__row"
Field Value
| Type | Description |
|---|---|
| string |
rows
The grid's row spans, y-up: top, middle, bottom, stretch.
Declaration
public static readonly Vector2[] rows
Field Value
| Type | Description |
|---|---|
| Vector2[] |
shiftHint
The hint explaining what Shift does. Exposed so a caller can localise it.
Declaration
public const string shiftHint = "Shift: Also set pivot"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The RectAnchorPresets main styling class.
Declaration
public const string ussClassName = "appui-rect-anchor-presets"
Field Value
| Type | Description |
|---|---|
| string |
Properties
anchorMax
The currently applied top-right anchor, used to highlight the matching preset. Unset — NaN — highlights nothing.
Declaration
[CreateProperty]
[UxmlAttribute]
public Vector2 anchorMax { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
anchorMin
The currently applied bottom-left anchor, used to highlight the matching preset. Unset — NaN — highlights nothing.
Declaration
[CreateProperty]
[UxmlAttribute]
public Vector2 anchorMin { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
Methods
GetCell(int, int)
One preset cell, indexed row-major from the top-left.
Declaration
public VisualElement GetCell(int row, int column)
Parameters
| Type | Name | Description |
|---|---|---|
| int | row | The row, 0..3, top to stretch. |
| int | column | The column, 0..3, left to stretch. |
Returns
| Type | Description |
|---|---|
| VisualElement | The cell element. |
IsSelected(int, int)
Whether one cell is the preset currently applied.
Declaration
public bool IsSelected(int row, int column)
Parameters
| Type | Name | Description |
|---|---|---|
| int | row | The row, 0..3. |
| int | column | The column, 0..3. |
Returns
| Type | Description |
|---|---|
| bool |
Events
picked
Raised when a preset is chosen.
Declaration
public event Action<RectAnchorPickEvent> picked
Event Type
| Type | Description |
|---|---|
| Action<RectAnchorPickEvent> |