Struct ScyllaUILength
A length value used throughout the Scylla UI layout system. Encodes both a numeric value and a unit mode (Absolute for reference pixels, Percent for a fraction of a parent dimension). Resolved against a property-specific parent dimension at solve time via Resolve(float).
Implements
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
[Serializable]
public struct ScyllaUILength : IEquatable<ScyllaUILength>
Remarks
ScyllaUILength is a value type and is fully serializable by Unity's Inspector. Use the static factories Absolute(float) and Percent(float) for clarity at call sites.
Percent values are expressed in 0..100 space (so 50 means
50% of the parent dimension). The solver multiplies by 0.01 internally
when resolving. The struct itself performs no clamping so designers can express
values outside the 0..100 range when intentional (for example, to bias a
spacer beyond a stack's edge).
Equality uses Approximately(float, float, float) on the value component and an exact comparison on the unit component.
Constructors
ScyllaUILength(float, ScyllaUILengthUnit)
Initializes a new ScyllaUILength with the supplied numeric value and unit mode.
Declaration
public ScyllaUILength(float value, ScyllaUILengthUnit unit)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The numeric value. |
| ScyllaUILengthUnit | unit | The unit mode used to interpret |
Fields
Zero
A length of zero, in Absolute mode.
Declaration
public static readonly ScyllaUILength Zero
Field Value
| Type | Description |
|---|---|
| ScyllaUILength |
Properties
IsAbsolute
true when this length uses absolute units.
Declaration
public bool IsAbsolute { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsPercent
true when this length uses percent units.
Declaration
public bool IsPercent { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Unit
The unit mode used to interpret Value.
Declaration
public ScyllaUILengthUnit Unit { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaUILengthUnit |
Value
The numeric value. Interpreted as reference-resolution pixels when
Unit is Absolute, or as a
percentage (0..100) when Unit is
Percent.
Declaration
public float Value { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
Absolute(float)
Creates a ScyllaUILength in absolute reference-resolution pixels.
Declaration
public static ScyllaUILength Absolute(float pixels)
Parameters
| Type | Name | Description |
|---|---|---|
| float | pixels | The pixel value, interpreted at the canvas reference resolution. |
Returns
| Type | Description |
|---|---|
| ScyllaUILength | A new ScyllaUILength in Absolute mode. |
Equals(ScyllaUILength)
Determines whether two ScyllaUILength values are approximately equal. Values are compared via Approximately(float, float, float) and units must match exactly.
Declaration
public bool Equals(ScyllaUILength other)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaUILength | other |
Returns
| Type | Description |
|---|---|
| bool |
Equals(object)
Returns true when obj is a ScyllaUILength
with the same unit mode and an approximately equal numeric value.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare against. |
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
GetHashCode()
Returns a hash code derived from the numeric value and unit mode of this length.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int |
Overrides
Percent(float)
Creates a ScyllaUILength in percent units. Values are expressed in
0..100 space (so 50 represents 50% of the resolved parent dimension).
Declaration
public static ScyllaUILength Percent(float percent)
Parameters
| Type | Name | Description |
|---|---|---|
| float | percent | The percent value in |
Returns
| Type | Description |
|---|---|
| ScyllaUILength | A new ScyllaUILength in Percent mode. |
Resolve(float)
Resolves this length against a parent dimension. Absolute values are returned
unchanged; percent values are multiplied by parentDimension
and divided by 100.
Declaration
public float Resolve(float parentDimension)
Parameters
| Type | Name | Description |
|---|---|---|
| float | parentDimension | The parent dimension against which to resolve a percent value. Ignored for absolute values. Pass the relevant dimension for the property being resolved (canvas height for top/bottom screen margins, stack width for left/right stack padding, main-axis size for spacing, etc.). |
Returns
| Type | Description |
|---|---|
| float | The resolved length in reference-resolution pixels. |
ToString()
Returns a string in the form "12 px" or "50 %" for debugging.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Operators
operator ==(ScyllaUILength, ScyllaUILength)
Returns true when left and right
have the same unit mode and approximately equal numeric values, as determined
by Equals(ScyllaUILength).
Declaration
public static bool operator ==(ScyllaUILength left, ScyllaUILength right)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaUILength | left | The left-hand operand. |
| ScyllaUILength | right | The right-hand operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(ScyllaUILength, ScyllaUILength)
Returns true when left and right
differ in unit mode or numeric value, as determined by the negation of
operator ==(ScyllaUILength, ScyllaUILength).
Declaration
public static bool operator !=(ScyllaUILength left, ScyllaUILength right)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaUILength | left | The left-hand operand. |
| ScyllaUILength | right | The right-hand operand. |
Returns
| Type | Description |
|---|---|
| bool |
|