AutoCanvasSize Public Module

A new version of this is available






Hi all,

I made a quick little module that will automatically change a ScrollingFrame’s CanvasSize.Y based on how many chlidren are in the ScrollingFrame.

Very useful when used in conjunction with UIGridLayout with CellSize using Offset.

I figured I’d make it public - you can find the code on my GitHub

In action:

https://i.gyazo.com/c2c5fdaa916ed4577489ab9e75daf07d.mp4

Edit: the core of this module was redundant, as UIGridLayouts and UIListLayouts have a read-only property for AbsoluteContentSize. I updated the module to use these properties as well as added support for UIListLayouts, and x-axis auto sizing.

52 Likes

This is awesome, I’ll probably use this in future games and/or plugins!

5 Likes

Definitely saving this for later! Thank you!

1 Like

I didn’t totally read through this, but can’t you just listen to .Changed on the UIGridLayout, and every time it’s changed, set the Y of the canvas to UIGridLayout.AbsoluteContentSize.Y?

as a bonus you can also add a UIPaddingConstraint that shifts the content over once the scrollbar appears to keep everything constant

2 Likes

I didn’t totally read through this, but can’t you just listen to .Changed on the UIGridLayout, and every time it’s changed, set the Y of the canvas to UIGridLayout.AbsoluteContentSize.Y?
as a bonus you can also add a UIPaddingConstraint that shifts the content over once the scrollbar appears to keep everything constant

You’re probably right :joy: :man_shrugging:

2 Likes

:stuck_out_tongue:

This is how I have this implemented in my current project

2 Likes

If your UIPadding value is the same as your scrollbar’s width, then couldn’t you use VerticalScrollBarInset? If you set it to Scrollbar in Studio, then it will automatically make the canvas size smaller on the X axis when the vertical scrollbar is shown. This can make the needed code here even shorter:

BuildItems.Changed:connect(function()
    BuildItems.CanvasSize = UDim2.new(0, 0, 0, BuildItems.UIGridLayout.AbsoluteContentSize.y)
end)
4 Likes

oh my god I didn’t know that existed, praise be the almighty Corecii :pray:

This is really useful! thank you so much im gonna use this :smiley:

I updated the module to use AbsoluteContentSize instead, as well as support for ListLayouts, also should support auto-sizing on the x axis as well. :+1:

Where’s the updated module that includes list layouts? I can’t find it. The link provided only supports Grid Layouts. Thanks

1 Like

I have updated the module, sorry about that.

Supports UIListLayout and x/y axis scaling.

2 Likes

Thanks!

Does it work with UI Gridlayout object?

Yes

1 Like

are they serverscripts or module scripts