surface.GetTextSize

From Garry's Mod
Jump to: navigation, search
 surface.GetTextSize( )

Contents

Description

Returns the width and height (in pixels) of the given text, but only if the font has been set with surface.SetFont.

Arguments

string text

The string to check the size of.

Returns

number

Width of the provided text

Returns

number

Height of the provided text

Examples

Example

Prints out the size of "Hello World" in the Trebuchet24 font.

surface.SetFont("Trebuchet24")

local message = "Hello World"
local width, height = surface.GetTextSize(message)

print("Text width: " .. width .. ", text height: " .. height)

Output:

Text width: 100, text height: 24


Examples

Example

Get text height very quickly. No tables or spare variables used.

local message = "Hello World"

surface.SetFont("Trebuchet24")
local height = select(2, surface.GetTextSize(message))

print(height)

Output:

24
Personal tools
Navigation