Class UDim
java.lang.Object
com.thecsdev.common.math.UDim
Represents a scalable dimension with both a proportional and absolute component.
This structure allows UI elements to be sized or positioned using a combination of:
- A relative
scalefactor (as a fraction of a reference size). - An absolute
offsetvalue (fixed pixel units).
finalValue = (referenceValue * scale) + offset;
This is useful for UI layouts that need to be responsive while maintaining fixed adjustments.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal UDimclone()final doublecomputeD(double referenceValue) Computes the final value using a double reference value.final floatcomputeF(float referenceValue) Computes the final value using a floating-point reference value.final intcomputeI(int referenceValue) Computes the final value using an integer reference value.final booleanfinal inthashCode()final StringtoString()
-
Field Details
-
ZERO
-
scale
public final double scaleThe proportional scale factor (relative to a reference size).A value of
1.0means the result is equal to the reference size, while0.5makes it half of the reference size. Negative values are valid and will scale in the opposite direction. -
offset
public final double offsetThe absolute offset (in pixels) added to the scaled value.This provides a fixed adjustment regardless of the reference size. A positive value shifts the result forward, while a negative value shifts it backward.
-
-
Constructor Details
-
UDim
public UDim() -
UDim
public UDim(double scale, double offset)
-
-
Method Details
-
hashCode
-
equals
-
clone
-
toString
-
computeI
public final int computeI(int referenceValue) Computes the final value using an integer reference value.The formula used is:
The result is rounded down to the nearest integer.finalValue = (referenceValue * scale) + offset;- Parameters:
referenceValue- The reference size to apply scaling to.- Returns:
- The computed final value as an integer.
-
computeF
public final float computeF(float referenceValue) Computes the final value using a floating-point reference value.The formula used is:
The result retains floating-point precision.finalValue = (referenceValue * scale) + offset;- Parameters:
referenceValue- The reference size to apply scaling to.- Returns:
- The computed final value as a float.
-
computeD
public final double computeD(double referenceValue) Computes the final value using a double reference value.The formula used is:
The result retains double precision.finalValue = (referenceValue * scale) + offset;- Parameters:
referenceValue- The reference size to apply scaling to.- Returns:
- The computed final value as a float.
-