UIGridLayout square?

How do I make it so the frames manipulated by UIGridLayout are always square? I’m pretty sure I have to do some math with the aspect ratio, but I don’t know what exactly.

I want this:

image

Instead of this:

image

And I can’t use offset because I’d like the buttons to resize with the screen resolution.

8 Likes

Easy, here are the sizes that I use:
{0.21, 0},{0.27, 0}

2 Likes

I don’t think it works like that?

This works for me, can I have a copy of your GUI so I can try figure this out?

It works when the parent frame is the exact same size, but what I want to do is keep the frames always square no matter the resolution or the size of the parent frame. It would be an easy fix if the UIGridLayout had a SizeConstraint like frames, imagelabels etc. do.

image

1 Like

This is by no means a solution to the problem.

What you are doing is using scale to size the frames and it just so happens that they look square due to the parent container size. If you were to view the UI on a screen with a different aspect ratio you would expect your frames to become rectangles. Perhaps you’re sizing absolutely instead, in which case then you can be certain what the scales need to be for them to remain square for all aspect rations.

The solution is not obvious but is actually fairly simple, when setting the cell size ensure that the y element is {1, 0} and the x element can be whatever you want, for example {0.25, 0}, {1, 0}. Once you’ve done this, insert a UIAspectRatioConstraint into your UIGridLayout and set the aspect ration to 1, this will ensure all cells are square.

53 Likes

Thanks from the future, it is definitely appreciated. I didn’t even know this was a thing. I was putting the UIAspectRatioConstraints into the individual frames and the alignment was weird, so this solved the problem I was having.

7 Likes

i couldve used that so long ago what the heck

5 Likes

Does this also work with UIListLayout or is that not necessary?

No, you just need to put the UIAspectRatios into all of the frames, it doesn’t work like that for UIListLayouts.

2 Likes