Scrollframe canvas resizing children

I have a scrolling frame UI object, and inside of it I have several button objects that are added when needed by script during game.

However, when I expand the canvas size to hold these, and to get the scroll bar to show up, all the buttons resize based on the canvas size, rather than the size of the visible viewport of the scrolling frame.

Is there any way to get the buttons to resize based on the frame size, not the canvas size?

3 Likes

You would use a GridLayout and UIAspectRatio as its child. This should keep all the images the same size.

4 Likes

It’s more likely than not that you are using Percents instead of Pixels!
UDim2.new(xPercent, xPixels, yPercent, yPixels)

Yeah, im using percents. I mean I can always use pixels and just calculate it each time the menu is opened, in case for some reason someone’s screen has changed size. But I thought it might be some setting or something that I was missing that could just do that on the auto.

Oh… Tom_atoes, I only just now saw your reply, I’ll try that.

Hi, this happened to me many times. I used pixels for the buttons, and to avoid any display problem when the screen size changes, I just add (may not be that efficient) 2 lines like:

local screengui = your screengui;
local defSize = screengui.AbsoluteSize.Y; --default screengui size
local buttonSizes = UDim2.new(idk,idk,idk,50); --for example

screengui.Changed:Connect(function(p)
if p=='AbsoluteSize' then
buttonsizes=(50*screengui.AbsoluteSize.Y)/defSize;
end
end)

for i,v in pairs(yourbuttonshere) do
v.size=udim2.new(stuff,stuff,stuff,buttonsizes)
end

Tell me if I’m not clear enough :sweat_smile:

3 Likes

Size the buttons using Offset, not Scale.

To get a similar effect to Scale, you can get the Scale value at the beginning for the X and Y Sizes of the GuiObject and then resize the GuiObject to:

UDim2.new(0, Scale.X * GuiObject.Parent.AbsoluteSize.X, 0, Scale.Y * GuiObject.Parent.AbsoluteSize.Y)

Bind a connection to GuiObject.Parent:GetPropertyChangedSIgnal(“AbsoluteSize”) and then resize the GuiObject whenever this happens and It should be fine.

11 Likes