Scaling library for Garry's Mod.
- Scaling that is based on your screen resolution*
- Automatic font scaling
- Registering sizes
- VGUI scaling**
- Parent relative VGUI scaling and positioning
*You'll need to add or set your screen resolution in code beforehand. By default it is set to Full HD.
**The result can be unexpectable for the VGUI elements that do not support scaling.
Scalar.RegisterResolution(string name, number width, number height)
Registers the resolution in the Scalar's resolution list for using it in Scalar.SetResolution()
- string name - ID of the resolution (e.g.: "HD", "8K").
- number width - Screen width.
- number height - Screen height.
Scalar.SetResolution(string name)
Sets the current working resolution, typically it's coder's screen resolution. This should be called before registering the size/font and scaling of the VGUI.
- string name - Name of the resolution.
Scalar.CheckMyResolution()
Checks if your screen resolution exists in the table.
- string Name of the resolution or bool false if not exists.
Scalar.RegisterFont(string fontName, number size, number minsize, table fontData)
Registers the font that will scale automatically when resolution is changed.
- string fontName - The new font name.
- number size - Normal size of font in pixels.
- number minsize - Minimal size of font in pixels.
- table fontData - https://wiki.facepunch.com/gmod/Structures/FontData
Scalar.SetResolution("QHD")
Scalar.RegisterFont("MenuFont", 16, 8,
{
font = "Arial",
extended = true,
weight = 500,
antialias = true,
})
Scalar.RegisterSize(string scaleName, number size, number minsize, [bool widthDependent = false])
Registers the size in global that will scale automatically when resolution is changed.
- string scaleName - The name of the scale. That's a global variable name
- number size - Normal size of scale in pixels.
- number minsize - Minimal size of scale in pixels.
- bool widthDependent - (Optional) Should this size be scaled in width or not. DEFAULT: false
Scalar.SetResolution("QHD")
Scalar.RegisterSize("UI_SCALE_HUD", 512, 64)
print(UI_SCALE_HUD)
Panel:SetParentRelativeScaling(bool enabled)
Enables or disables parent relative scaling. DEFAULT: Disabled
- bool enabled - Should parent relative scaling be enabled or not.
Panel:SetPixelScaling(bool enabled)
Enables or disables pixel scaling. DEFAULT: Disabled
- bool enabled - Should pixel scaling be enabled or not.
Scalar.SetResolution("QHD")
Scalar.RegisterFont("SCALAR_DEMO_FONT", 64, 12,
{
font = "Arial",
extended = true,
weight = 500,
antialias = true,
})
local fr = vgui.Create("DFrame")
fr:SetTitle("Scaling Test")
fr:SetParentRelativeScaling(true)
fr:SetSize(0.5, 0.5)
fr:SetPos(0.25, 0.25)
fr:SetParentRelativeScaling(false)
fr:MakePopup()
local text = fr:Add("DLabel")
text:SetFont("SCALAR_DEMO_FONT")
text:SetText("It takes 1/4 of the screen space")
text:SetPixelScaling(true)
text:SetPos(32, 360 - 32)
text:SetSize(1000, 64)
text:SetPixelScaling(false)