TL:DR - Is it possible to get the current offset of a Gui frame if its default height is set by scale. If not can you suggest an alternative method for changing CanvasSize of a scrolling frame to meet the height of its children.
Long version
What I want to do is when the player clicks a button a ScrollingFrame appears filled with playerStats frames for each player on the server. If the combinded height of the players stats frames is greater than the size of the ScrollingFrame then I want to make the CanvasSize increase.
I’m trying to make it look something like this Normal
CanvasSize increased
The ScrollingFrame has a Y scale of 0.65. The playerStats frame has Y offset of 20. If the combinded Y offset of the playerStats frames inside the Scrolling frame is greater than its current offset then the CanvasSize Y offset increases. Is it possible to get the offset of the scrolling frame since its height is set by scale?
Additional information
I’ve tried setting the playerStats size by scale but this causes them to scale with the CanvasSize of the ScrollingFrame (If you know a way to make them scale with the Size of the ScrollingFrame that would be helpful).
Here’s a custom player list I made a while back, it’s a good example of a ScrollingFrame list that correctly resizes to contain all the entries in the list.
The most relevant part is a function that’s called every time an entry is added or removed, and which updates the CanvasSize of the ScrollingFrame:
function updateListCanvas()
--If there are too many players to show at once in the playerList, the CanvasSize of the List needs
-- to be set accordingly so that the player can scroll through and see all the entries.
local pixelPadding = 0
pixelPadding += list.UIListLayout.Padding.Offset
pixelPadding += list.UIListLayout.Padding.Scale * list.Parent.AbsoluteSize.Y
local listCanvasHeight = 0 --Height of the canvas in pixels
listCanvasHeight += #getListEntryChildren(list) * listEntryPrefab.AbsoluteSize.Y
listCanvasHeight += (#getListEntryChildren(list) - 1) * pixelPadding
list.CanvasSize = UDim2.new(0, 0, 0, listCanvasHeight)
end
The pixelPadding stuff is to calculate how large the gaps are between the elements. The gap comes from the UIListLayout.Padding property.
The first line that increments listCanvasHeight adds the height of an element times the number of elements.
The second one adds the gap size times the number of gaps (number of elements minus 1).
Are you looking for something like AbsolutePosition or AbsoluteSize? I don’t think I’m understanding your issue very well.
Additionally, UIGridLayouts (including UIListLayouts) have an AbsoluteContentsSize property which represents the full size of the list. I think this might be what you’re looking for.