Struct UIPadding
Represents the internal spacing (padding) inside a UI element, expressed as individual per-side pixel values for left, right, top, and bottom edges.
Implements
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public readonly struct UIPadding : IEquatable<UIPadding>
Remarks
Padding describes the space inside an element's border, between the border and the element's content. For external spacing (space between an element and its siblings or parent boundary), use UIMargin instead.
UIPadding is a readonly value type. All mutation methods
(e.g. WithLeft(float), Scale(float)) return a new instance
rather than modifying the receiver, making it safe to pass by value without
defensive copies.
Equality comparisons use Mathf.Approximately so that minor floating-point
rounding differences do not produce false negatives.
UIPadding and UIMargin can be explicitly converted to each
other. Use the explicit cast operators when the same spacing values need to serve
both purposes.
Several named presets are available as static properties: Zero, Small, Medium, Large, and ExtraLarge.
Constructors
UIPadding(float)
Initializes a new UIPadding with the same pixel value applied to all four sides.
Declaration
public UIPadding(float uniform)
Parameters
| Type | Name | Description |
|---|---|---|
| float | uniform | The padding value in pixels to apply uniformly to the left, right, top, and bottom sides. Negative values are stored but typically produce content that overflows the container boundary. |
UIPadding(float, float)
Initializes a new UIPadding with separate horizontal and vertical padding values. The horizontal value is applied equally to left and right; the vertical value is applied equally to top and bottom.
Declaration
public UIPadding(float horizontal, float vertical)
Parameters
| Type | Name | Description |
|---|---|---|
| float | horizontal | The padding value in pixels applied to both the left and right sides. |
| float | vertical | The padding value in pixels applied to both the top and bottom sides. |
UIPadding(float, float, float, float)
Initializes a new UIPadding with individually specified values for each side.
Declaration
public UIPadding(float left, float right, float top, float bottom)
Parameters
| Type | Name | Description |
|---|---|---|
| float | left | The left padding in pixels. |
| float | right | The right padding in pixels. |
| float | top | The top padding in pixels. |
| float | bottom | The bottom padding in pixels. |
Properties
Bottom
Gets the bottom padding in pixels. This is the space between the element's bottom border and its bottommost content edge.
Declaration
public float Bottom { get; }
Property Value
| Type | Description |
|---|---|
| float |
ExtraLarge
Gets a UIPadding with a uniform 24-pixel padding on all sides. Suitable for prominent dialog-style containers that require significant internal breathing room around their content.
Declaration
public static UIPadding ExtraLarge { get; }
Property Value
| Type | Description |
|---|---|
| UIPadding |
Horizontal
Gets the sum of the left and right padding values in pixels. Useful when calculating the total horizontal space consumed by padding (e.g. to determine the available width for content inside a container).
Declaration
public float Horizontal { get; }
Property Value
| Type | Description |
|---|---|
| float |
IsUniform
Gets a value indicating whether all four sides of this padding have the same value. Comparison uses Approximately(float, float, float) to tolerate minor floating-point imprecision.
Declaration
public bool IsUniform { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
IsZero
Gets a value indicating whether all four sides of this padding are zero. Comparison uses Approximately(float, float, float) to tolerate minor floating-point imprecision.
Declaration
public bool IsZero { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Large
Gets a UIPadding with a uniform 16-pixel padding on all sides. Suitable for panels or cards where content should have generous separation from the container border.
Declaration
public static UIPadding Large { get; }
Property Value
| Type | Description |
|---|---|
| UIPadding |
Left
Gets the left padding in pixels. This is the space between the element's left border and its leftmost content edge.
Declaration
public float Left { get; }
Property Value
| Type | Description |
|---|---|
| float |
Medium
Gets a UIPadding with a uniform 8-pixel padding on all sides. A versatile default for most container layouts that need comfortable internal spacing.
Declaration
public static UIPadding Medium { get; }
Property Value
| Type | Description |
|---|---|
| UIPadding |
Right
Gets the right padding in pixels. This is the space between the element's right border and its rightmost content edge.
Declaration
public float Right { get; }
Property Value
| Type | Description |
|---|---|
| float |
Small
Gets a UIPadding with a uniform 4-pixel padding on all sides. Suitable for compact containers where content needs minimal breathing room.
Declaration
public static UIPadding Small { get; }
Property Value
| Type | Description |
|---|---|
| UIPadding |
Top
Gets the top padding in pixels. This is the space between the element's top border and its topmost content edge.
Declaration
public float Top { get; }
Property Value
| Type | Description |
|---|---|
| float |
Vertical
Gets the sum of the top and bottom padding values in pixels. Useful when calculating the total vertical space consumed by padding (e.g. to determine the available height for content inside a container).
Declaration
public float Vertical { get; }
Property Value
| Type | Description |
|---|---|
| float |
Zero
Gets a UIPadding with all four sides set to zero pixels. Use this as a default when no internal spacing is required.
Declaration
public static UIPadding Zero { get; }
Property Value
| Type | Description |
|---|---|
| UIPadding |
Methods
Equals(UIPadding)
Determines whether this UIPadding is equal to another
UIPadding using per-side Mathf.Approximately comparisons.
Declaration
public bool Equals(UIPadding other)
Parameters
| Type | Name | Description |
|---|---|---|
| UIPadding | other | The UIPadding to compare against. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Determines whether this UIPadding is equal to the given object.
Returns false if obj is not a UIPadding.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare against. |
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
GetHashCode()
Computes the hash code for this UIPadding based on the exact floating-point values of all four sides.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | An integer hash code derived from Left, Right, Top, and Bottom. Note that because equality uses approximate comparison, two instances that compare as equal may produce different hash codes if their raw float values differ slightly. |
Overrides
Scale(float)
Returns a new UIPadding with all four side values multiplied by the given scale factor. Useful for DPI-aware scaling or responsive layout adjustments.
Declaration
public UIPadding Scale(float factor)
Parameters
| Type | Name | Description |
|---|---|---|
| float | factor | The scalar multiplier applied to each side. A value of |
Returns
| Type | Description |
|---|---|
| UIPadding | A new UIPadding where each side equals the original value multiplied
by |
ToRectOffset()
Converts this UIPadding to a UnityEngine.RectOffset suitable for
use with Unity uGUI layout groups such as HorizontalLayoutGroup and
VerticalLayoutGroup which expect integer padding via padding fields.
Declaration
public RectOffset ToRectOffset()
Returns
| Type | Description |
|---|---|
| RectOffset | A new UnityEngine.RectOffset whose integer fields are set by rounding each
side's pixel value using |
ToString()
Returns a human-readable string representation of this UIPadding.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | If IsUniform is |
Overrides
WithBottom(float)
Returns a new UIPadding that is identical to this instance except with the Bottom side replaced by the specified value.
Declaration
public UIPadding WithBottom(float bottom)
Parameters
| Type | Name | Description |
|---|---|---|
| float | bottom | The new bottom padding value in pixels. |
Returns
| Type | Description |
|---|---|
| UIPadding | A new UIPadding with Bottom set to |
WithLeft(float)
Returns a new UIPadding that is identical to this instance except with the Left side replaced by the specified value.
Declaration
public UIPadding WithLeft(float left)
Parameters
| Type | Name | Description |
|---|---|---|
| float | left | The new left padding value in pixels. |
Returns
| Type | Description |
|---|---|
| UIPadding | A new UIPadding with Left set to |
WithRight(float)
Returns a new UIPadding that is identical to this instance except with the Right side replaced by the specified value.
Declaration
public UIPadding WithRight(float right)
Parameters
| Type | Name | Description |
|---|---|---|
| float | right | The new right padding value in pixels. |
Returns
| Type | Description |
|---|---|
| UIPadding | A new UIPadding with Right set to |
WithTop(float)
Returns a new UIPadding that is identical to this instance except with the Top side replaced by the specified value.
Declaration
public UIPadding WithTop(float top)
Parameters
| Type | Name | Description |
|---|---|---|
| float | top | The new top padding value in pixels. |
Returns
| Type | Description |
|---|---|
| UIPadding | A new UIPadding with Top set to |
Operators
operator +(UIPadding, UIPadding)
Adds two UIPadding instances together, combining their per-side values. Useful for accumulating padding from multiple sources such as a base style and a per-element override.
Declaration
public static UIPadding operator +(UIPadding a, UIPadding b)
Parameters
| Type | Name | Description |
|---|---|---|
| UIPadding | a | The first padding. |
| UIPadding | b | The second padding to add to |
Returns
| Type | Description |
|---|---|
| UIPadding | A new UIPadding where each side equals the sum of the corresponding
sides of |
operator ==(UIPadding, UIPadding)
Returns a value indicating whether two UIPadding instances are equal,
using per-side Mathf.Approximately comparisons.
Declaration
public static bool operator ==(UIPadding left, UIPadding right)
Parameters
| Type | Name | Description |
|---|---|---|
| UIPadding | left | The first UIPadding to compare. |
| UIPadding | right | The second UIPadding to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
explicit operator UIPadding(UIMargin)
Explicitly converts a UIMargin to a UIPadding by copying all four side values unchanged. This is useful when the same spacing values need to serve as both external margin and internal padding.
Declaration
public static explicit operator UIPadding(UIMargin margin)
Parameters
| Type | Name | Description |
|---|---|---|
| UIMargin | margin | The UIMargin to convert. |
Returns
| Type | Description |
|---|---|
| UIPadding | A new UIPadding whose Left, Right,
Top, and Bottom values equal the corresponding
values of |
explicit operator UIMargin(UIPadding)
Explicitly converts a UIPadding to a UIMargin by copying all four side values unchanged. This is useful when the same spacing values need to serve as both internal padding and external margin.
Declaration
public static explicit operator UIMargin(UIPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| UIPadding | padding | The UIPadding to convert. |
Returns
| Type | Description |
|---|---|
| UIMargin | A new UIMargin whose left, right, top, and bottom values equal
the corresponding values of |
operator !=(UIPadding, UIPadding)
Returns a value indicating whether two UIPadding instances are not equal.
Declaration
public static bool operator !=(UIPadding left, UIPadding right)
Parameters
| Type | Name | Description |
|---|---|---|
| UIPadding | left | The first UIPadding to compare. |
| UIPadding | right | The second UIPadding to compare. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator *(UIPadding, float)
Multiplies a UIPadding by a scalar value, scaling all four sides proportionally. Delegates to Scale(float).
Declaration
public static UIPadding operator *(UIPadding padding, float scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| UIPadding | padding | The padding to scale. |
| float | scalar | The scalar multiplier. |
Returns
| Type | Description |
|---|---|
| UIPadding | A new scaled UIPadding. |
operator *(float, UIPadding)
Multiplies a scalar value by a UIPadding, scaling all four sides proportionally. Delegates to Scale(float). This overload supports scalar-on-the-left syntax.
Declaration
public static UIPadding operator *(float scalar, UIPadding padding)
Parameters
| Type | Name | Description |
|---|---|---|
| float | scalar | The scalar multiplier. |
| UIPadding | padding | The padding to scale. |
Returns
| Type | Description |
|---|---|
| UIPadding | A new scaled UIPadding. |
operator -(UIPadding, UIPadding)
Subtracts one UIPadding from another on a per-side basis. Useful for computing the difference between two padding values or removing a known padding contribution from a cumulative value.
Declaration
public static UIPadding operator -(UIPadding a, UIPadding b)
Parameters
| Type | Name | Description |
|---|---|---|
| UIPadding | a | The padding to subtract from. |
| UIPadding | b | The padding to subtract from |
Returns
| Type | Description |
|---|---|
| UIPadding | A new UIPadding where each side equals the corresponding side of
|