Get current pixel height of a Gui frame (Filling a ScrollingFrame Gui with frames)

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
NotFull

CanvasSize increased
OverFull

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).

1 Like

You can use AbsolutePosition and AbsoluteSize.

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.

Custom PlayerList.rbxl (30.5 KB)

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).

1 Like

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.

3 Likes