Best ways of using Scrw and Scrh

Ive had some problems with sizing vgui elements, i’ve tried using scrh and w so it apparently changes its size correctly to the screen resolution and its not working for me

	local LuckFrame = vgui.Create("DFrame")
		local x = 1366
		local y = 768

		local ScreenW = ScrW( ) / x
		local ScreenH = ScrH( ) / y

		LuckFrame:SetPos(300* ScreenW, 300* ScreenH)
		LuckFrame:SetSize(300* ScreenW, 200* ScreenH)
		LuckFrame.Paint = function()
			draw.RoundedBox( 2, 0, 0, LuckFrame:GetWide(), LuckFrame:GetTall(), Color( 31,31,32 ) )
			draw.RoundedBox( 2, 0, 190* ScreenH, LuckFrame:GetWide(), LuckFrame:GetTall(), Color( 27,27,28 ) )

Im not really a fan of that method neither and wondering is there a better way of doing it?

Why do you set the position, if you Center it afterwards anyway?

Yep, there are better ways. For example you could ScrW() * [0-1] to get the same positions on every screen size.

Heres the git to what i was making:

If i change resolution the sizes are messed up etc. Would using Scrw() - amount and ScrH() - amount work for sizing and positioning?

Here’s how I did my Map Vote sizing, I probably should’ve send you these code snippets earlier :confused:

Basically I made everything lined up on my resolution using constants (100, 700) and then later started changing the sizes to work on different resolutions.


ExitButton:SetSize( Frame:GetWide()/29.5, Frame:GetTall()/37.2 )
ExitButton:SetPos( Frame:GetWide() - ExitButton:GetWide() - 10, 10 ) 

MapArea:SetPos(Frame:GetWide() / 36, Frame:GetTall() / 3.9)
MapArea:SetSize(Frame:GetWide()/ 1.06, Frame:GetTall()/ 1.45)

A tip i got from someone from the site.
This is the way of making it work cross resolution on 16:9 if im not mistaken.

local xScreenRes = 1920
local yScreenRes = 1080
local wMod = ScrW() / xScreenRes
local hMod = ScrH() / yScreenRes

Then you can use the wMod and hMod as variables but multiplying them

DermaPanel:SetPos(wMod * 500, hMod * 280)
DermaPanel:SetSize(wMod * 600, hMod * 500)