Class UIAnchors
Provides a library of pre-configured UIAnchor presets covering the nine standard alignment positions and common stretch configurations, together with factory methods for custom and alignment-driven anchors.
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public static class UIAnchors
Remarks
All preset properties are static read-only instances initialized at class load time, so they carry no per-call allocation cost.
The nine point-anchor presets (UpperLeft through LowerRight)
each set anchorMin and anchorMax to the same value (no stretch),
and align the pivot to match the anchor corner. The anchored position offset is
zero on all presets; use WithPosition(Vector2)
to add a pixel offset after retrieving a preset.
The stretch presets differ by setting anchorMin and anchorMax to
different values so the element resizes with the parent. Stretch
fills the parent entirely; the directional variants stretch along one axis only.
Use FromAlignment(UIAlignment) to obtain the nine-point preset that corresponds to a UIAlignment enum value. Use Custom(float, float) or Custom(float, float, float, float) for positions not covered by the named presets. Use CreateStretch(float, float, float, float) for partial-range stretch configurations.
Properties
LowerCenter
Gets a UIAnchor positioned at the horizontal center of the parent's
bottom edge. Anchor point: (0.5, 0). Pivot: (0.5, 0).
Declaration
public static UIAnchor LowerCenter { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
LowerLeft
Gets a UIAnchor positioned at the lower-left corner of the parent.
Anchor point: (0, 0). Pivot: (0, 0).
Declaration
public static UIAnchor LowerLeft { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
LowerRight
Gets a UIAnchor positioned at the lower-right corner of the parent.
Anchor point: (1, 0). Pivot: (1, 0).
Declaration
public static UIAnchor LowerRight { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
MiddleCenter
Gets a UIAnchor positioned at the exact center of the parent.
Anchor point: (0.5, 0.5). Pivot: (0.5, 0.5).
Declaration
public static UIAnchor MiddleCenter { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
MiddleLeft
Gets a UIAnchor positioned at the vertical center of the parent's
left edge. Anchor point: (0, 0.5). Pivot: (0, 0.5).
Declaration
public static UIAnchor MiddleLeft { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
MiddleRight
Gets a UIAnchor positioned at the vertical center of the parent's
right edge. Anchor point: (1, 0.5). Pivot: (1, 0.5).
Declaration
public static UIAnchor MiddleRight { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
Stretch
Gets a UIAnchor that stretches the element to fill the entire parent
rectangle both horizontally and vertically.
anchorMin: (0, 0), anchorMax: (1, 1), pivot: (0.5, 0.5).
Declaration
public static UIAnchor Stretch { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
StretchBottom
Gets a UIAnchor that stretches the element horizontally across the
full parent width and pins it to the bottom edge.
anchorMin: (0, 0), anchorMax: (1, 0), pivot: (0.5, 0).
Declaration
public static UIAnchor StretchBottom { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
StretchHorizontalCenter
Gets a UIAnchor that stretches the element horizontally across the
full parent width while centering it vertically on the parent's midpoint.
anchorMin: (0, 0.5), anchorMax: (1, 0.5), pivot: (0.5, 0.5).
Declaration
public static UIAnchor StretchHorizontalCenter { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
StretchLeft
Gets a UIAnchor that stretches the element vertically across the
full parent height and pins it to the left edge.
anchorMin: (0, 0), anchorMax: (0, 1), pivot: (0, 0.5).
Declaration
public static UIAnchor StretchLeft { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
StretchRight
Gets a UIAnchor that stretches the element vertically across the
full parent height and pins it to the right edge.
anchorMin: (1, 0), anchorMax: (1, 1), pivot: (1, 0.5).
Declaration
public static UIAnchor StretchRight { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
StretchTop
Gets a UIAnchor that stretches the element horizontally across the
full parent width and pins it to the top edge.
anchorMin: (0, 1), anchorMax: (1, 1), pivot: (0.5, 1).
Declaration
public static UIAnchor StretchTop { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
StretchVerticalCenter
Gets a UIAnchor that stretches the element vertically across the
full parent height while centering it horizontally on the parent's midpoint.
anchorMin: (0.5, 0), anchorMax: (0.5, 1), pivot: (0.5, 0.5).
Declaration
public static UIAnchor StretchVerticalCenter { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
UpperCenter
Gets a UIAnchor positioned at the horizontal center of the parent's
top edge. Anchor point: (0.5, 1). Pivot: (0.5, 1).
Declaration
public static UIAnchor UpperCenter { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
UpperLeft
Gets a UIAnchor positioned at the upper-left corner of the parent.
Anchor point: (0, 1). Pivot: (0, 1).
Declaration
public static UIAnchor UpperLeft { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
UpperRight
Gets a UIAnchor positioned at the upper-right corner of the parent.
Anchor point: (1, 1). Pivot: (1, 1).
Declaration
public static UIAnchor UpperRight { get; }
Property Value
| Type | Description |
|---|---|
| UIAnchor |
Methods
CreateStretch(float, float, float, float)
Creates a stretch anchor that spans a sub-region of the parent defined by the given normalized min and max boundaries. The pivot is automatically placed at the center of the resulting anchor region.
Declaration
public static UIAnchor CreateStretch(float minX, float minY, float maxX, float maxY)
Parameters
| Type | Name | Description |
|---|---|---|
| float | minX | Normalized X position of the left boundary within the parent (0-1). |
| float | minY | Normalized Y position of the bottom boundary within the parent (0-1). |
| float | maxX | Normalized X position of the right boundary within the parent (0-1).
Must be greater than or equal to |
| float | maxY | Normalized Y position of the top boundary within the parent (0-1).
Must be greater than or equal to |
Returns
| Type | Description |
|---|---|
| UIAnchor | A new UIAnchor with |
Custom(float, float)
Creates a custom point anchor where the anchor min, anchor max, and pivot are all set to the same normalized position, placing the element at an arbitrary point within the parent with its pivot aligned to the anchor.
Declaration
public static UIAnchor Custom(float x, float y)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | Normalized X position within the parent (0-1). |
| float | y | Normalized Y position within the parent (0-1). |
Returns
| Type | Description |
|---|---|
| UIAnchor | A new UIAnchor with |
Custom(float, float, float, float)
Creates a custom point anchor at the specified normalized position with an independently specified pivot. Use this variant when you need the element to be anchored at one point but have its pivot at a different relative location (e.g. anchor at top-center, pivot at bottom-center for a tooltip that appears above its anchor).
Declaration
public static UIAnchor Custom(float x, float y, float pivotX, float pivotY)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | Normalized X anchor position within the parent (0-1). |
| float | y | Normalized Y anchor position within the parent (0-1). |
| float | pivotX | X component of the pivot point, normalized within the element (0-1). |
| float | pivotY | Y component of the pivot point, normalized within the element (0-1). |
Returns
| Type | Description |
|---|---|
| UIAnchor | A new UIAnchor with |
FromAlignment(UIAlignment)
Returns the UIAnchor preset that corresponds to the specified UIAlignment value, providing a convenient bridge between the high-level alignment enum and the low-level anchor struct.
Declaration
public static UIAnchor FromAlignment(UIAlignment alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| UIAlignment | alignment | The UIAlignment value to convert. Must be one of the nine defined enum values; any other value throws. |
Returns
| Type | Description |
|---|---|
| UIAnchor | One of the nine point-anchor presets: UpperLeft, UpperCenter, UpperRight, MiddleLeft, MiddleCenter, MiddleRight, LowerLeft, LowerCenter, or LowerRight. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |