Scrolling Frame CanvasSize

According to the wiki, CanvasSize is:

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

This leads me to think that when the frame is scrolled to its bottom, the CanvasPosition.Y should equal:
(Frame.AbsoluteSize.Y*Frame.CanvasSize.Y.Scale)+Frame.CanvasSize.Y.Offset

Is that not right?

My tests have been finding very different results.


Test A:

ScrollingFrame with an AbsoluteSize of (200,200), and a CanvasSize of (0,0,2,0).

Expected bottom CanvasPosition: 400
Actual bottom CanvasPosition: 1172

Test B:

ScrollingFrame with an AbsoluteSize of (300,300), and a CanvasSize of (0,0,2,0).

Expected bottom CanvasPosition: 600
Actual bottom CanvasPosition: 1072

Test C:

ScrollingFrame with an AbsoluteSize of (500,500), and a CanvasSize of (0,0,2,0).

Expected bottom CanvasPosition: 1000
Actual bottom CanvasPosition: 872


What? Where is that number coming from? Why is it shrinking as AbsoluteSize increases? What calculation have I wildly missed?

They all end with 72, so there’s clearly a simple, static equation here that I’m overlooking, and I’m sure I’ll facepalm once I find out the answer.


Edit:
I’d love a feature of just Frame.ScrollWindowSize that acts as an AbsoluteSize of the scrollable window. Please.

1 Like

How are you getting the “Actual bottom CanvasPosition”?

Scroll till you can’t anymore, and then check the CanvasPosition property.

1 Like

If you nest your ScrollingFrame under a Frame of the same size as the ScrollingFrame itself, you’ll get the results you expected.

EDIT: Just note that CanvasPosition is the top-left of the canvas, so you’ll need to subtract your expectations by the absolute height of the frame.

3 Likes

So if it’s in a ScreenGui, you use Mouse.ViewSizeY?

ScreenGuis have their own AbsoluteSize property.

Where is this documented?
https://developer.roblox.com/en-us/api-reference/class/ScreenGui

It’s not a direct member of screengui, instead its one of the inherited members of GuiBase2d.

1 Like

A bit off-topic, but the has devhub been broken for a while now. Inherited properties aren’t displayed. For example, here’s the documentation for Part:

image

ScreenGui inherits from LayerCollector, which, in turn, inherits from GuiBase2d. You’ll find the properties you’re looking for there:

This property is also displayed in the Properties window:

image

Anyway, if you want a more reliable API reference, there’s this:

1 Like

Ohhhh. Thank you so much.

Working while DevHub is broken is not fun. :frowning:

Huge thank you to @XAXA and @Halalaluyafail3, this equation works exactly as expected.

math.abs((Frame.Parent.AbsoluteSize.X*Frame.CanvasSize.X.Scale)+Frame.CanvasSize.X.Offset-Frame.AbsoluteSize.X)

2 Likes