I have a ScrollingFrame and there can be infinite descendants, and I want that frame to have a CanvasSize large enough to scroll through each and every descendant.
If you know the answer, then please reply.
Thanks!
Yes, I was pondering this just yesterday. I think the AbsoluteSize and TextBounds properties should help you.
assuming you're using a UIListLayout or a UIGridLayout to lay out each ui element in the ScrollingFrame, you can use the AbsoluteContentSize
property to automatically resize it
UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function() ScrollingFrame.CanvasSize = UDim2.new(0, UIListLayout.AbsoluteContentSize.X, 0, UIListLayout.AbsoluteContentSize.Y) end) ScrollingFrame.CanvasSize = UDim2.new(0, UIListLayout.AbsoluteContentSize.X, 0, UIListLayout.AbsoluteContentSize.Y) -- update it if there are already ui elements in the frame
otherwise you'll have to manually iterate over descendants, and find the position of the outermost element
local maxX = -math.huge -- in case you have elements with a negative position for...some reason local maxY = -math.huge for _, child in pairs(ScrollingFrame:GetChildren()) do -- if the elements have their own children which go outside their bounds then you'll have to change this to GetDescendants maxX = math.max(maxX, child.AbsolutePosition.X + child.AbsoluteSize.X) maxY = math.max(maxY, child.AbsolutePosition.Y + child.AbsoluteSize.Y) end ScrollingFrame.CanvasSize = UDim2.new(0, maxX - ScrollingFrame.AbsolutePosition.X, 0, maxY - ScrollingFrame.AbsolutePosition.Y)
Closed as Not Constructive by JesseSong
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?