How to work out the size for an unknown amount of textlabels in a scrollingui

Hi!

I have a ScrollingFrame with a UILayout, I have a function to iterate through elements in a list and create a TextLabel for them, I then put the TextLabels inside the scrollingframe. The scrollingframe doesn’t always fit all the options, I can fix this by editing it’s canvas side. However I need to know which size I should make it each time.

Since I’m using scale for my TextLabels, growing the ScrollingFrameCanvasSize will just grow the textlabels and have no relative difference.

I could use offset but then it wouldn’t work on all devices as well as it does now.
Thanks!

1 Like

If the scrolling frame/canvas doesn’t grow in the X direction then you should be able to base the text label scale off of that.

2 Likes

What I’ve done in these situations is I create a Template with my desired scaling outside the ScrollingFrame. When I create my TextLabels they get an offset based on the AbsoluteSize of my Template.

This gives a non-changing size for the TextLabels, which means they wont expand from more items in the ScrollingFrame. However this also means they won’t change size if the user changes ScreenSize after their creation. This is not a common occurence.

However, @Emskipo’s solution is probably better. By using an AspectRatioConstraint you should be able to “ignore” the Y component and simply scale it using the X component.

2 Likes