UI Automatic Size
UI Automatic Size
The AutomaticSize property automatically resizes a parent UI object to the size of its descendants. By applying this property, you can dynamically add content and the parent’s size will adjust to fit that content.
TextLabelwith AutomaticSize property of Y and
Frame(grey) with AutomaticSize property of XY containing a child frame (yellow) with animating position
Automatic sizing can be used in many ways, including:
|Localized Text||Expand a UI object to fit text that has been
|User Input||Allow the player to
|Scrolling Frames||Automatically resize the
|Rich Text||Automatically adjust the size of text objects using
Setup / Behavior
GuiObject/AutomaticSize|AutomaticSize is available on any
GuiObject. To configure it, select the object and choose an option for the AutomaticSize property.
ScrollingFrameuses the AutomaticCanvasSize property instead of AutomaticSize. It behaves the same but resizes the frame's
ScrollingFrame/CanvasSize|CanvasSize, not its base
Automatic sizing can be configured for specific control over which direction(s) the UI object will resize to fit the content.
|XY||Horizontal + Vertical|
Just as when you’re regularly sizing an object, automatic sizing will take the anchor point into consideration. Compare the following three automatically-sized text labels:
When automatic sizing is applied to an object, its minimum size is controlled by the object’s
GuiObject/Size|Size property, meaning the parent object won’t be resized smaller than its size along any axis.
When a text object has the
TextLabel/TextWrapped|TextWrapped property enabled and an AutomaticSize setting of Y or XY, the label will resize to accommodate text that wraps across multiple lines.
Instead of enabling the TextScaled property for text objects, it’s recommended that you use AutomaticSize. For more details, see the
The following script creates an automatically-sized parent frame with a
UIListLayout, then it inserts several automatically-sized
TextLabel objects. Note how the parent
UIListLayout automatically resizes to fit its child content and the labels automatically resize to fit their text content. This script should be parented to a
TextBox objects are more expensive to calculate when they are automatically sized because the text bounds must be calculated using the maximum available space determined by automatic size. This functionality is optimized for performance, but be deliberate in your use of the
GuiObject/AutomaticSize|AutomaticSize setting on text objects.
Other than text objects, automatically-sized objects perform about equally with their non-automatically-sized counterparts.