Skip to content

drawRect

Draws an unfilled rectangle outline between two defined points on the screen or canvas.

ui.drawRect(p1, p2, color, rounding, roundingFlags, thickness)

This function renders a hollow rectangle. The shape is defined by an axis-aligned bounding box calculated from points p1 (usually top-left) and p2 (usually bottom-right).

ParameterTypeRequiredDefaultDescription
p1vec2Yes-Screen coordinates for the first corner of the rectangle.
p2vec2Yes-Screen coordinates for the opposite corner of the rectangle.
colorrgbmYes-The color and opacity of the outline.
roundingnumberNo0.0The radius of the corners in pixels.
roundingFlagsui.CornerFlagsNoui.CornerFlags.AllBitmask determining which corners apply the rounding radius.
thicknessnumberNo1.0The width of the outline stroke in pixels.
  • None

Draw a simple red box with default thickness and sharp corners.

local startPos = vec2(10, 10)
local endPos = vec2(100, 50)
local red = (1, 0, 0, 1)
-- draw a red rectangle
ui.drawRect(startPos, endPos, red)