ViewSizeChanged event request!

Hello!

Notice

I’m TeaAndCopy. This feature request comes only from Webmotion. As he isn’t in the devforum, I said I would post his ideas for him. Please note I am only the messenger in this instance. Every useful piece of feedback will be sent directly to him.

Feature

I digress, this feature would look like this:

game:GetService('UserInputService').ViewSizeChanged

This event would fire when the client’s window size is changed.

Use Case

-- Local Script
game:GetService('UserInputService').ViewSizeChanged:connect(function(x, y)
   -- x, y would represent the new ViewSizeX and ViewSizeY (Absolute size of the screen in pixels)
   print('new ViewSizeX: ' .. x .. ', new ViewSizeY: ' .. y)
   
   -- This event could also be used to position scaled Gui objects, for example:
   local textlabel = script.Parent:FindFirstChild('TextLabel')
   textlabel.SizeConstraint = Enum.SizeConstraint.RelativeYY
   textlabel.Size = UDim2.new(0.8, 0, 0.8, 0)
  
   textlabel.Position = UDim2.new(0.5, -(textlabel.AbsoluteSize.X/2), 0.1, 0)
   -- The AbsoluteSize of the object will be changed when the window is resized, so we need to position the object again.
end)

Without the event above, the TextLabel would remain at the same position as before when the window is resized.

Alternatives

However, there are other ways to re-position the object, for example using this:

textlabel.Position = UDim2.new(0.5, -(textlabel.AbsoluteSize.X/2), 0.1, 0) -- Using this in a while loop

You could also make this work using scale on a XY Constraint which would mean you can position them using scale.
However if you’re using YY or XX SizeConstraints, a script would be needed to position the object directly in the centre of the X or Y axis, depending on which constraint you’re using.

Please post your thoughts & opinions below as myself and Webmotion would love to hear what you think of this idea.

-Tea & Web

7 Likes

So basically

workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
	print("New size:", workspace.CurrentCamera.ViewportSize)
end)

works with minimizing/maximizing, snapping the window etc., as I just tested it.

41 Likes