Skip to content

useSize

Lucy.useSize returns a getter for a GUI object’s size in the units you lay it out in: its AbsoluteSize without the UIScales on it and above it. Lucy scales every scene to the device, so a measured AbsoluteSize is in screen pixels and does not compare with the offsets you write; this does. The getter follows the object as it resizes and as the scene rescales, so a binding that reads it updates by itself.

Use it when a size depends on the room something ends up with: cards as tall as the body under a header, a column that takes what a row leaves. Don’t listen to AbsoluteSize and work out the scale yourself.

Usage

local size = Lucy.useSize(target)
ArgumentTypeWhat it is
targetGuiObject?, a ref or a getterThe object to measure. A ref or a getter is followed, so it can be set later

Returns

NameTypeWhat it is
size() -> Vector2Its size in layout units. Vector2.zero while there is no object or it is not laid out yet

A change of less than a hundredth of a point is left out. Inside a scaled panel, layout can move an object’s size back and forth by a tiny fraction of a point as it settles; a size that followed that would make a layout built on it chase it round and round.

It needs an owner, like every composable: a component’s render, a scene’s build, or an effect scope.

Example: Club Lucy’s reward cards fill the body

The body under the header takes whatever height the screen leaves. The cards are two rows, as tall as that allows:

local body = Lucy.new "Frame" {
    Position = UDim2.fromOffset(0, HEADER),
    Size = UDim2.new(1, 0, 1, -HEADER),
    BackgroundTransparency = 1,
    Parent = panel,
}
local room = Lucy.useSize(body)
local function card(): number
    return math.max(72, (room().Y - GAP) // 2)
end

Lucy.new "Frame" {
    Size = function()
        return UDim2.fromOffset(card(), card())
    end,
    Parent = body,
}