world.WindowTextWidth

MUSHclient script function (Method) — introduced in version 4.34

Calculates the width of text in a miniwindow

Prototype

long WindowTextWidth(BSTR WindowName, BSTR FontId, BSTR Text, BOOL Unicode);

Data type meanings

Description

This calculates how many pixels a particular piece of text will take up, which can help in calculating how big a window to create, or where to put other things. Note that WindowText returns the number of pixels when it draws text, so you don't need to call WindowTextWidth simply to work out where to draw the very next item.

WindowName - the name of an existing miniwindow.

FontId - a font id that you have loaded.

Text - the text to be calculated (maximum of 8192 characters)

Unicode - if true, the text is Unicode text in UTF-8 format

For more information, see:

http://www.gammon.com.au/mushclient/mw_text.htm

Lua example

width   = WindowTextWidth (win, "f", "Lazy dog yawns")  -- width of text

Return value

If successful, returns the number of pixels the text would take horizontally.

If unsuccessful, returns a negative number as follows:

-1 : That window name does not exist
-2 : That font was not loaded
-3 : For Unicode, invalid UTF-8 sequence

Related topic

MiniWindows

See also

FunctionDescription
WindowCreateCreates a miniwindow
WindowFontLoads a font into a miniwindow
WindowFontInfoReturns information about a font
WindowFontListLists all fonts loaded into a miniwindow
WindowTextDraws text into a miniwindow