Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ScrollingFrame (List GUI) not scaling properly?

Asked by
RafDev 109
7 years ago

I'm using a ScrollingFrame and adding a TextLabel for each item in a list-fashion. However, the bigger the list, the bigger the text becomes, and, instead of fitting all items to the ScrollingFrame's Canvas, they are cut off after the 20th item.

Summarized code below:

k = 0
for i,v in pairs(items) do
    scrollingFrame.CanvasSize = UDim2.new(1,0,k*.05,0)
    local itemLabel = Instance.new("TextLabel", scrollingFrame)
    itemLabel.Size = UDim2.new(1,0,.05,0)
    itemLabel.Position = UDim2.new(0,0,(scrollingFrame.CanvasSize.Y.Scale/.05)*k,0)
    itemLabel.Text = "Item #" .. i
    itemLabel.TextScaled = true
    k = k + 1
end

Practical example: https://i.gyazo.com/7a8f6e3b9310bda8195568d8fcfbbe9e.gif (note there are 50+ commands)

Thank you in advance.

1 answer

Log in to vote
1
Answered by 7 years ago

The reason the text is getting bigger the longer the list goes is due to you using the Scale property in the position. Try using Offset for the items, but you can still use Scale for the actual frame's size.

Also, you shouldn't manually position the buttons as there is a new way to do so with ROBLOX's new UIListLayout. You can configure padding, sizes of objects, and you don't need to manually position them, simply parent them into the ScrollingFrame.

After adding a UIListLayout, use this code to fix your problem:

for i,v in pairs(items) do
    scrollingFrame.CanvasSize = UDim2.new(1,0,0,20) -- Edit the offset Y to however big you make the objects
    local itemLabel = Instance.new("TextLabel", scrollingFrame)
    -- UIListLayout takes care of the positioning and sizing for you, no need to do it here.
    itemLabel.Text = "Item #" .. i
    itemLabel.TextScaled = true
end

If I helped, upvote and accept my answer! :)

0
I've never used this before, so this may be something really simple - but everything is very big and clustered now - http://prntscr.com/f2ttxf . Any idea on how to fix? RafDev 109 — 7y
0
Try editing the padding joritochip 705 — 7y
Ad

Answer this question