AutoCanvasSize Public Module


#1

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:

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.


#2

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


#3

Definitely saving this for later! Thank you!


#4

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


#5

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:


#6

:stuck_out_tongue:

This is how I have this implemented in my current project


#7

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)

#8

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


#9

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


#10

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:


#11

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


#13

I have updated the module, sorry about that.

Supports UIListLayout and x/y axis scaling.


#14

Thanks!


#15

Does it work with UI Gridlayout object?


#16

Yes