Garry's Mod Wiki

ScreenScale

  number ScreenScale( number size )

Description

Returns a number based on the size argument and the players' screen width. This is used to scale user interface (UI) elements to be consistently sized and positioned across all screen resolutions.

The width is scaled in relation to 640x480 resolution, and does not take into account non the aspect ratio. See example below for how to adjust or that.

This function can also be used for scaling font sizes.

See ScreenScaleH for a function that scales from height.

Arguments

1 number size
The position or size you want to scale within 640 pixel wide screen.

Returns

1 number
The scaled number based on the player's screen width.

Example

Prints a scaled number based on the number 96, 400 and 640.

print( ScreenScale( 96 ) ) print( ScreenScale( 400 ) ) print( ScreenScale( 640 ) )
Output: 252, 1050, 1680 (this will differ depending on your screen width. Here the screen width is 1680.)

Example

Adjust for non 4:3 aspect ratios.

print( ScreenScale( 96 ) / ( ScrW() / ScrH() ) )