Flex Features for UIListLayout Client Release

[Update] August 20, 2024

Flex is now live on all platforms!


Hi Developers!

We’re excited to announce the client release of Flex for UIListLayout! Thank you for all your feedback, messages, and excitement around this feature during the Studio Beta. Flex is a set of new UIListLayout features that allows your UI content to effortlessly fill a dynamically-sized UI container using these new features:

  • Multiline wrapping :leftwards_arrow_with_hook:
  • Growing items to fill empty space / shrinking items if they don’t fit :straight_ruler:
  • Distributing empty space between elements :milky_way:
  • Custom per-item line alignment options :control_knobs:

Check out UIListLayout and UIFlexItem for further documentation.

Please note that Flex is live on all client devices except Quest VR today. If you’re planning to enable your experience on Quest, we recommend temporarily avoiding the use of Flex in your implementation. We’re actively working on resolving bugs here and will keep you all updated.
Update: Flex is now live on all platforms!


Terminology

  • Flex container: a GuiBase2D with a UIListLayout child
  • Flex direction (or fill direction): the direction specified by UIListLayout.FillDirection
  • Cross direction: direction perpendicular to the fill direction
  • Flex item: a GuiObject child in a flex container
  • Basis size: the size of a flex item before stretching/growing is applied
  • Flex size: the size of a flex item after stretching/growing is applied
  • Flex line: a rectangle within a container containing multiple flex items
    • The line’s flex size is the width or height of the container, depending on UIListLayout.FillDirection
    • The line’s cross size is determined by the largest item cross size in the line
    • The line’s rectangle always completely contains every item in the line

How to create with Flex

Let’s look at a simple example of making a “spacer” element that fills empty space in a container.

  1. Create a UIListLayout containing two TextLabels and the “spacer” element, a Frame.
  2. Set the TextLabels to a known size, such as 100 x 100px.
  3. Add a UIFlexItem component to the spacer Frame.
  4. Set the UIFlexItem.FlexMode = Fill so that the spacer fills the remaining space.

Your setup should look like this:

If you resize the parent container, notice that the spacer fills up the extra horizontal space between the two TextLabels!

Example: Shop UI

Flex features can be used across multiple UI elements to create a holistic feature, like a shop! We made a Flex demo place that uses all the new Flex features so you can get a taste of Flex in action. To access this place in Studio, go to the link above, click the 3 dots in the upper right corner, and click “Edit in Studio”.

Here’s what you’ll see when you open this place:

As you adjust the screen size of Studio, you’ll see how the Shop UI adjusts to small and large screen sizes to display the same information efficiently. All the shop items are accessible regardless of screen size – Flex ensures that the text isn’t too small to read or the buttons aren’t too small to tap on.

In the Explorer widget, you can find the instance tree:

Let’s dive deeper into the Flex features we used here:

  • The ScrollingFrame has a UIListLayout component with HorizontalFlex = Fill and VerticalFlex = Fill. This tells each item in the list to grow horizontally and vertically to fit the container, if there is room.
  • The UIListLayout has Wraps = true which allows the items to take up multiple lines.
  • The icons have a UIFlexItem component with FlexMode = Custom and GrowFactor = 0.5, so they grow half as much as the text (which has GrowFactor 1 by default).
  • Each item has a UISizeConstraint minSize of 120px in the Y direction, preventing the height of each item from being squished too much.
  • The shop is wrapped in a ScrollingFrame so that overflowing items can be scrolled to on small screens.
  • The ScrollingFrame has AutomaticCanvasSize = Y so that the canvas is sized to fit the content.

To the user, here’s how this UI would look on some different mobile and desktop screens:

APIs

New UIListLayout Properties
Property Value Options Description
UIListLayout.FillDirection Horizontal, Vertical (default) The main axis aka flex direction of the layout.
UIListLayout.Wraps False (default), True If true, allows multiple content lines to be created perpendicular to the FillDirection.
UIListLayout.HorizontalFlex None (default), Fill, SpaceAround, SpaceBetween, SpaceEvenly If not None, distribute extra horizontal space using this strategy.
UIListLayout.VerticalFlex None (default), Fill, SpaceAround, SpaceBetween, SpaceEvenly If not None, distribute extra vertical space using this strategy.
UIListLayout.ItemLineAlignment Automatic (default), Start, Center, End, Stretch Cross-axis alignment of items within each line.
New UIFlexItem Instances
Property Value Options Description
UIFlexItem.FlexMode: Enum.UIFlexMode
None (default), Grow, Shrink, Fill, Custom
How the parent GuiObject should grow or shrink with available space in the parent UIListLayout.
UIFlexItem.ItemLineAlignment: Enum.ItemLineAlignment
Automatic (default), Start, Center, End, Stretch
Cross-axis alignment of this specific instance within the line.
GrowRatio: float
Positive number
If FlexMode=Custom, and there is empty space in the line, this is the weighting factor for distributing the empty space to this specific item in order to fill the line.

This property is only shown in Studio if FlexMode=Custom.
ShrinkRatio: float
Positive number
If FlexMode=Custom, and there is overflow in the line, this is the weighting factor for shrinking this specific item in order to fit all items in 1 line.

This property is only shown in Studio if FlexMode=Custom.

New Enums

UIFlexAlignment
Enum.UIFlexAlignment Value Description
None (default) How the parent GuiObject should grow or shrink with available space in the parent UIListLayout.
Fill Set all child items to have an effective GrowRatio=1 and ShrinkRatio=1.
SpaceAround Distribute space evenly between all items in the flex direction. The start and end padding is half the between-element padding. Note for SpaceAround, SpaceBetween, and SpaceEvenly, the spacing size is at least UIListLayout.Padding.
SpaceBetween Distribute space evenly between all items in the flex direction. The start and end padding is zero.
SpaceEvenly Distribute space evenly between all items in the flex direction. The start and end end padding is equal to the between-element padding.

ItemLineAlignment
Enum.ItemLineAlignment Value Description
Automatic (default) Follow the UIListLayout.HorizontalAlignment or UIListLayout.VerticalAlignment, depending on the FillDirection.

This is the default value for backwards-compatibility.
Start Align items within each line to the top for FillDirection.Horizontal or left for FillDirection.Vertical.
Center Align items in each line to the center of the line.
End Align items in each line to the bottom for FillDirection.Horizontal, or right for FillDirection.Vertical.
Fill Fill entire line cross direction, overriding the original item cross size.

UIFlexMode
Enum.UIFlexMode Effective GrowRatio Effective ShrinkRatio
None (default) 0 0
Grow 1 0
Shrink 0 1
Fill 1 1
Custom UIFlexItem.GrowRatio UIFlexItem.ShrinkRatio

Limitations

  • How many items can I include within a Flex layout? While there is no hard limit, we recommend having less than 1000 items in your Flex layout to maintain performance quality. We are working to expand this capability in the future.
  • Can I use AutomaticSize and Flex together? There are some interactions between AutomaticSize and UIFlexItem that are not currently supported, e.g. using non-zero anchor points, scaled size-items, scaled padding, and TextScaled. We are working to address these issues in the future.

:blue_heart: Made with love

Flex Layouts was made possible due to the remarkable contributions of @stadium_parkour2, @uiuxartist, @EGOTISMS, @CharlieGordonnn, @DrRanchDressing, @darthskrill, and @Slim_Fandango. Thanks for all your help and support in making Flex Layouts! :clap:

We can’t wait to hear your thoughts on Flex Layouts and see all the amazing things you create! Let us know about your experience and if you encounter any issues! :smile:

376 Likes

This topic was automatically opened after 10 minutes.

The wait for this felt like genuine centuries, finally we have proper dynamic UI.

55 Likes

This looks so useful! I just opened studio and found all the flex materials! I love how it makes it so that the text is never too small so that mobile users can still read it! Can’t wait to try it!!!

22 Likes

Fantastic, have the flickering issues in studio been fixed ahead of the client release?

20 Likes

This a fire addition to the List Layouts

19 Likes

Thank you for making this update🙏

This is actually useful for the list layouts, I really can’t wait to try this in studio!!:grin:

19 Likes

Finally! Thank you devs!!!

16 Likes

Huge Roblox W. Thank you devs!!

14 Likes

There is a problem: when I duplicate the button (this is shown in the video), it turns out to be smaller than the others. I use the FILL property (see my UIList settings screenshot below). The video shows that the new button is smaller in width than the others. However, if you press CTRL+Z once or twice, the size becomes correct. What is the reason for this?
image

16 Likes

my dream has come true… thank you devs for a game-changing (literally) feature update

15 Likes

IT TOOK AGES

but its finally there c:

14 Likes

LETSSSS FRICKING GOOOO OMG I HATE YOU GUYS FOR DELAYING THIS SOO MUCH SHAHAHHAHSBSH!

I had to remake my games gui because of you!

My joy is uncountable but so is my anger.

14 Likes

I love how roblox ui design is coming closer and closer to CSS. As an aspiring full-stack web developer, I can’t say I don’t love this update.

13 Likes

ascending-energy

22 Likes

The wait felt like 2 years. But anyways, IT’S FINALLY HERE, I LOVE ITTTT

Thank you so much for real, this will help A LOT :heart:

15 Likes

No more using plugins to do this!

14 Likes

The first bug you posted [Flickering UI Elements ONLY in Studio] unfortunately has not been fixed yet, but it will be worked on soon! I’ll post an update when it’s fixed!

The second bug you posted [Automatic sized UI going crazy - jiggling and rescaling] should already be fixed!

Thanks for reporting this, it looks like a bug! Would you be able to share the UI in the screenshot as an rbxm or rbxl (in a PM if you would like) so I can debug further? I tried to repro with a UIListLayout with ImageButtons but I wasn’t able to see this issue. Thank you!

[Resolved] The issue was caused by the AutoScale plugin overriding the size of new instances.

10 Likes

Thank you for releasing this, I already had stuff made with flex but couldn’t use it

9 Likes

This is a massive W! Thank you Roblox! :wink:

8 Likes