I’ve tried countless things, I cannot for the life of me figure out how to do this: scale a scrolling frame to adapt when new items are added into it, I want the items to keep their original size but the scrolling frame will be able to scroll down to the bottom how many frames or whatever is added there are.
TLDR: function to automatically scale a scrolling frame based on new frames being added, keep frames Y size (IN SCALE, NO OFFSET) so that it doesn’t cut off scrolling ability after a few frames and goes all the way down.
I don’t have any current code since I scrapped it all. If anyone can help me, it would be greatly appreciated.
local function ScaleScroll(scroller: ScrollingFrame)
local Layout: UIListLayout? = scroller:FindFirstChildWhichIsA("UIListLayout")
local UIPadding: UIPadding? = scroller:FindFirstChildWhichIsA("UIPadding")
local TotalYSize = 0
local Padding = 0
local PaddingOffsetTop = 0
local PaddingOffsetBottom = 0
if Layout then
Padding = Layout.Padding.Scale
end
if UIPadding then
PaddingOffsetTop = UIPadding.PaddingTop.Offset
PaddingOffsetBottom = UIPadding.PaddingBottom.Offset
end
for _, v in pairs(scroller:GetChildren()) do
if v:IsA("Frame") or v:IsA("TextButton") or v:IsA("ImageButton") or v:IsA("ScrollingFrame") or v:IsA("ImageLabel") or v:IsA("VideoFrame") or v:IsA("ViewportFrame") or v:IsA("TextLabel") then
TotalYSize += v.Size.Y.Scale
TotalYSize += Padding
end
end
scroller.CanvasSize = UDim2.new(0, 0, TotalYSize, (PaddingOffsetTop + PaddingOffsetBottom))
end
Will it also work for UI grid layouts? If not it’s alright.Do you run it after all the frames are in or after each frame is in (I’m using a for loop to add frames to the container)
So unfortunately, this did not work. The frames have gotten larger, (which I don’t think is correct) and I can only scroll past a few frames. Do you know what could be causing this?
function ScrollScale(ScrollingFrame: ScrollingFrame)
local Grid = ScrollingFrame:FindFirstChildWhichIsA("UIGridLayout")
ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, Grid.AbsoluteContentSize.Y+15)
end
I’m using a UIGridLayout, and its size is using frame too, not offset.
local frame: ScrollingFrame = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").ScrollingFrame
local grid: UIGridLayout = frame:FindFirstChildWhichIsA("UIGridLayout")
local default_size = 100 -- size in pixels of frames in the scrolling frame
frame.ChildAdded:Connect(function(_)
frame.CanvasSize = UDim2.new(0, 0, 0, grid.AbsoluteContentSize.Y+15)
for _,v: Frame in ipairs(frame:GetChildren()) do
if v.ClassName ~= "UIGridLayout" then
grid.CellSize = UDim2.new(grid.CellSize.X, UDim.new(default_size / frame.AbsoluteCanvasSize.Y, 0))
end
end
end)
function ScrollScale(ScrollingFrame: ScrollingFrame)
local Grid: UIGridLayout? = ScrollingFrame:FindFirstChildWhichIsA("UIGridLayout")
local DefaultSize = script.Template.AbsoluteSize.Y
ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, Grid.AbsoluteContentSize.Y+15)
for _,v: Frame in ipairs(ScrollingFrame:GetChildren()) do
if v.ClassName ~= "UIGridLayout" then
Grid.CellSize = UDim2.new(Grid.CellSize.X, UDim.new(DefaultSize / ScrollingFrame.AbsoluteCanvasSize.Y, 0))
end
end
end