Layout, input and lifetime
Size and position
Section titled “Size and position”LUI uses logical units: the host scales them for the display. For a dimension,
the resolved value is parent size × Scale + Offset. UDim2 holds one such pair
for width/X and another for height/Y.
Button.Size = UDim2.fromOffset(180, 44) -- A fixed logical size.Panel.Size = UDim2.new(1, -32, 1, -32) -- Parent size minus 32 on each axis.Panel.Position = UDim2.fromOffset(16, 16) -- A 16-unit top/left margin.This fragment assumes Button and Panel already exist. For the panel above, the remaining 16 units on the right/bottom complete the margin. Use UDim2 for a complete example.
Position identifies the point selected by AnchorPoint. With AnchorPoint (0,0),
that is the top-left corner. With (0.5,0.5), it is the center. AbsoluteSize and
AbsolutePosition are the resolved measurements; read them rather than assigning
them.
Arrange a list
Section titled “Arrange a list”Replace Src/Main.luau in a basic starter with this complete example:
local Window = Instance.new("Window", { Title = "LUI example", Size = UDim2.fromOffset(560, 280),})local Status = Instance.new("TextLabel", { Parent = Window, Text = "Ready", Position = UDim2.fromOffset(16, 170), Size = UDim2.new(1, -32, 0, 72),})local Content = Instance.new("Frame", {Parent = Window, Size = UDim2.fromOffset(320, 140)})Instance.new("UIListLayout", {Parent = Content, FillDirection = "Vertical", Padding = UDim.new(0, 8)})for Index = 1, 3 do Instance.new("TextButton", {Parent = Content, Text = "Action " .. Index, Size = UDim2.fromOffset(220, 36), LayoutOrder = Index})endWindow.Visible = trueExpected result: three vertically stacked buttons with eight-unit gaps. UIListLayout arranges their positions; LayoutOrder chooses their order. Use UIPadding for space around the container and UIGridLayout for a grid.
Scroll longer content
Section titled “Scroll longer content”local Window = Instance.new("Window", { Title = "LUI example", Size = UDim2.fromOffset(560, 280),})local Status = Instance.new("TextLabel", { Parent = Window, Text = "Ready", Position = UDim2.fromOffset(16, 170), Size = UDim2.new(1, -32, 0, 72),})local List = Instance.new("ScrollingFrame", { Parent = Window, Size = UDim2.fromOffset(320, 140), CanvasSize = UDim2.fromOffset(320, 480),})Instance.new("UIListLayout", {Parent = List, Padding = UDim.new(0, 8)})for Index = 1, 10 do Instance.new("TextLabel", {Parent = List, Text = "Row " .. Index, Size = UDim2.fromOffset(280, 36), LayoutOrder = Index})endList.CanvasPosition = Vector2.new(0, 80)Window.Visible = trueExpected result: a short viewport shows part of a taller list. CanvasSize declares the scrollable extent; CanvasPosition requests an offset. The final clamped value is AbsoluteCanvasPosition. ScrollingFrame clips its children.
Handle actions before raw input
Section titled “Handle actions before raw input”Use Button.Activated for an ordinary action. It represents supported button
activation rather than only a mouse press. For a custom right-click menu or
drag gesture, use InputBegan/InputChanged/InputEnded and check Device before
reading pointer-only fields. IsCanceled distinguishes a canceled pointer gesture
from a completed release. The input example and
complete right-click recipe
show the difference.
Clean up a screen
Section titled “Clean up a screen”local Screen = Instance.new("Frame", {Parent = Window})local Button = Instance.new("TextButton", {Parent = Screen, Text = "Continue"})Button.Activated:Connect(function() Button.Text = "Ready" end)
-- When leaving this screen:Screen:Destroy()This fragment assumes Window exists. Destroying Screen also destroys the button and disconnects its signals. Calling Destroy again is safe. Setting Parent to nil only detaches an object; it does not destroy it.
Keep shared application data outside the screen if it must survive navigation. Service subscriptions and work started independently by the application need their own cleanup. The modular tutorial shows a screen switch that destroys the old screen before creating the next.
Text input and deeper details
Section titled “Text input and deeper details”Use TextChanged to read committed Text. An input method can temporarily compose text before committing it; that preview is separate. Custom selection uses zero-based Unicode scalar offsets (code points), not UTF-8 byte offsets or necessarily visible-character counts. Ordinary fields do not need custom selection handling. Read TextBox when implementing an editor or secret-entry flow.
Inspect Layout starts a separate copy of the app’s Luau state. It helps inspect the shared tree and geometry, but it does not attach to your existing native window or qualify host-specific input behavior.