UDim2
UDim2
is a utility class representing a 2D size or position using both scale and offset components.
It is commonly used in Weo for UI element positioning and sizing.
UDim2 Utility
Constructor
UDim2.new()
Function
UDim2.new(xScale, xOffset, yScale, yOffset)
- Creates a new UDim2 instance.
Parameters:
xScale
number- Scale component for X axis (0-1).
xOffset
number- Offset in pixels for X axis.
yScale
number- Scale component for Y axis (0-1).
yOffset
number- Offset in pixels for Y axis.
Returns:
UDim2
UDim2- The created UDim2 instance.
Throws an error if any parameter is not a number.
Methods
UDim2:Lerp()
Method
UDim2:Lerp(other, alpha)
- Linearly interpolates between this UDim2 and another.
Parameters:
other
UDim2- The target UDim2 to interpolate towards.
alpha
number- Interpolation factor (0-1).
Returns:
UDim2
UDim2- A new UDim2 instance.
Operators
__add
Operator
- Adds two UDim2 values.
- Usage:
result = udim2A + udim2B
- Returns:
UDim2
__sub
Operator
- Subtracts two UDim2 values.
- Usage:
result = udim2A - udim2B
- Returns:
UDim2
__eq
Operator
- Checks equality of two UDim2 values.
- Usage:
isEqual = udim2A == udim2B
- Returns:
boolean
__tostring
Operator
- Returns a human-readable string representation.
- Usage:
string = tostring(udim2)
- Returns:
string
Example
local position = UDim2.new(0.5, 10, 0.3, -5)
local size = UDim2.new(0.8, 0, 0.4, 20)
-- Interpolation
local startPos = UDim2.new(0, 0, 0, 0)
local endPos = UDim2.new(1, 0, 1, 0)
local interpolated = startPos:Lerp(endPos, 0.5)
-- Operations
local combined = position + size
local difference = position - size
local isEqual = position == size
local posString = tostring(position)