Skip to content

UIVector

Global · UIVector · server and client scripts

UIVector is an immutable 2D UI coordinate combining fractional parent Scale (Vector2) and fixed Points (Vector2). Add, subtract, negate, or blend UIVectors with +, -, unary -, and :Lerp.

Example

-- Client script: size a panel to half the parent plus 20 points.
local panel = World.Spawn({ Box = {}, Panel = {} })
local box = panel.Box
if box then
    box.Size = UIVector.new(0.5, 0.25, 20, 10)
end

new

Function
new(scaleX: number, scaleY: number, pointsX: number, pointsY: number) -> UIVector

UIVector.new creates a UIVector from scaleX, scaleY, pointsX, and pointsY.

Example

-- Client script: build a combined scale and points size.
local size = UIVector.new(0.5, 0.5, -16, -16)
print(size.Scale.X, size.Points.X)

fromScale

Function
fromScale(x: number, y: number) -> UIVector

UIVector.fromScale creates a UIVector with Scale set to (x, y) and zero points.

Example

-- Client script: fill the parent container.
local full = UIVector.fromScale(1, 1)
print(full.Scale.X, full.Scale.Y)

fromPoints

Function
fromPoints(x: number, y: number) -> UIVector

UIVector.fromPoints creates a UIVector with Points set to (x, y) and zero scale.

Example

-- Client script: fixed-size button in points.
local buttonSize = UIVector.fromPoints(160, 44)
print(buttonSize.Points.X, buttonSize.Points.Y)

Zero

PropertyRead only
Zero: UIVector

UIVector.Zero is the zero UIVector (0, 0, 0, 0).

Default UIVector.new(0, 0, 0, 0)