My ScrollingFrame won't scroll

Hi,

I have set up a scrolling frame with a list layout and some padding. As this screenshot shows, the content very clearly goes outside the frame when I turn off ClipsDescendants:

(pardon the huge padding at the top, I stripped back tons of UI stuff so it looks a bit weird)

The position and size of the scrolling frame, for reference:

Now, I add a script which sets the canvas size based on the contents of the list layout:

local TweenService = game:GetService("TweenService")

local scroll = script.Parent.Scroll

local layout = scroll:FindFirstChildWhichIsA "UIGridStyleLayout"
if not layout then return end

local function resize()
	local size = layout.AbsoluteContentSize
	scroll.CanvasSize = UDim2.new(0, size.X, 0, size.Y)
end
resize()

layout:GetPropertyChangedSignal "AbsoluteContentSize":Connect(resize)

The expected result is that the scrolling frame would show the scrollbar and be scrollable both via dragging the scrollbar and by scrolling the mouse wheel:

image

However, the actual result is a bit weirder, as the scrollbar is not visible and I cannot scroll with the mouse wheel, and I can’t drag where the scrollbar would be either. It does still reserve space for the scrollbar however:

The AbsoluteSize of the scrolling frame as reported by Studio is 640x430.
The AbsoluteContentSize of the list layout is 610x436.
The CanvasSize set by the local script above is also 610x436.

The scrolling does however start working when the canvas size becomes significantly different from the scrolling frame size.

Here’s a model containing the problematic frame:
scrollingframe.rbxm (8.6 KB)

Is there a way to fix this?

2 Likes

The scrollbar will only show up when the CanvasSize’s height is bigger than the frame, however when counting the content size you’re getting the offset which isn’t as big as the frame.

Set the CanvasSize Y scale to 1 and it should show up.

scroll.CanvasSize = UDim2.new(0, size.X, 1, size.Y)

Edit: This is false, and not the actual issue.

I’m not at my PC to test this, but wouldn’t this just make the canvas one screen taller, thus introducing a ton of whitespace under the content? This is what the wiki says about it:

The UDim2 is calculated using the parent gui’s size, similar to the regular Size property on gui objects.

I would prefer tight sizing if possible; if I’m wrong then please do correct me :slight_smile:

1 Like

It seems I am wrong, you are correct.

Alright, so the issue is your Padding layout. You don’t account for the padding whenever calculating the size.

This is a very simple fix

	local size = layout.AbsoluteContentSize;
	local padding = layout.Parent.UIPadding;
	
	size = size + Vector2.new(0, padding.PaddingBottom.Offset + padding.PaddingTop.Offset);
	scroll.CanvasSize = UDim2.new(0, size.X, 0, size.Y)

This will add 66 offset (will be different if you change the padding) to your final size because UIListLayout’s AbsoluteContentSize property does not take padding into account.

This will make it very tightly sized, and does work for me. (at least on my computer)

6 Likes

FWIW, this behavior is intentional - AbsoluteContentSize deliberately does not include the padding imposed by a UIPadding instance. The correct solution is to factor the padding in like above.

The scrolling frame should not be reserving space for the vertical scrollbar. I’ll look into this one.

4 Likes

If anyone still needs another solution. In ScrollingFrame Properties go to Scrolling then VerticalScrollBarInset and choose always.

2 Likes