UIAspectRatioConstraint not working correctly?

I don’t want to constrain size - I want to constrain ratio. I want the image to be square.

SizeConstraint will make it square. It keeps the aspect ratio.

Yes but I also want it to scale with the thing it is in across multiple resolutions. The entire point of the this was to fill up the unused areas of a frame.

Unfortunately that still doesn’t solve the issue - the size is still being defined by the height, not the width.

I guess I’ll make a bug report.

That’d make it even easier to use the SizeConstraint property - and set it to RelativeXX.

I don’t fully see what you’re trying to do… but seems like SizeConstraint would do the job. (Could you expand on what exactly you’re trying to achieve?)

I’m trying to make a blurred background for a map (ever seen like those vine videos where the background is a blurred copy of the mobile phone resolution video?).

The map may sometimes not scale to fit the rectangular frame properly, as it needs to stay square. My solution to make it not look horrible is to steal the idea from what I said above.

But, like I said, I don’t want to touch size. The only thing that is important is resolution, as size is already defined and working properly.

Ah. If I understand correctly, you’re trying to keep the white imagelabel square, and scaling by width.
image
The UIAspectRatioConstraint is not working as you want it to, because of this frame’s size;
image
image
It only scales with height, because, it’s a descendant of this frame - which only scales with height also. It’s width(X) is in offset, so all of it’s descendants will have an offset width regardless whether it’s using scale or not.

exactly, the width is supposed to be consistent while the height is not

the issue here is that it’s not scaling to that constant width, it’s scaling to height instead, even when it’s supposed to be scaling by width

Are you looking for something like this (except with ClipsDescendants and no Transparency)?

Yes! :slight_smile:

1 Like

For some reason, UIAspectRatioConstraint doesn’t have this built in by default. I call this mode CoverMinSize, and it doesn’t exist. :frowning: It’s the opposite of ScaleWithParentSize.

Comparison between ScaleWithParentSize and CoverMinSize

The white in the following images is the constrained GUI element. I’ve disabled ClipsDescendants and made it transparent in order to illustrate my point.


ScaleWithParentSize:

The frame stays within its boundaries at all times. The DominantAxis doesn’t matter.

CoverMinSize:

The frame covers its boundaries at all times. The DominantAxis doesn’t matter.

It looks like FitWithinMaxSize is supposed to be a single-axis CoverMinSize, except the axis chooser is broken! Even if you could choose the axis, I don’t think it would give you what you want since you’d need to change the dominant axis depending on whether height or width is the bigger axis.


Here is a feature request post for it.


Until this is an actual feature, you can use a super-simple script and the SizeConstraint property to do this. The “CoverMinSize” examples were achieved that way.

local gui = script.Parent
local parent = gui.Parent

local function update()
	gui.SizeConstraint =
		parent.AbsoluteSize.x < parent.AbsoluteSize.y
		and Enum.SizeConstraint.RelativeYY
		 or Enum.SizeConstraint.RelativeXX
end

update()
parent:GetPropertyChangedSignal("AbsoluteSize"):Connect(update)

(Ideally placed where the rest of your GUI programming is done)

Example file: UIAspectRatioConstraintCoverMinSize.rbxl (18.0 KB)

3 Likes

Alright, thanks.

Didn’t really think about SizeConstraint :wink: