Name
TextWidth -- return the width of a string
Synopsis
width = TextWidth(string$[, t])
Deprecated syntax
width = TextWidth(string$[, encoding])
Library
text

Function
This function returns the width of the text specified by string$ if it was rendered on the display. So it takes care of the currently selected font as well as the font style.

Please note: This function returns the cursor advancement of the text. This is often less than the text actually occupies when rendered to the display. If you need detailed information about the real extent of a text, please use the function TextExtent() instead.

Starting with Hollywood 10.0, this function accepts an optional table argument that allows you to specify the following additional options:

Encoding:
This tag can be used to specify the character encoding used by string$. This defaults to the character encoding set as the text library default encoding using SetDefaultEncoding(). See SetDefaultEncoding for details. (V10.0)

Charspacing:
Allows you to adjust the space between characters. You can set this to a positive or negative value. A positive value will increase the space between characters, a negative value will decrease it. (V10.0)

Inputs
string$
source text
t
optional: table argument containing further options (see above) (V10.0)
Results
width
width of the text
Example
width = TextWidth("Hello World")
pos = (640 - width) / 2
Locate(pos, 0)
Print("Hello World")
The above code centers the text "Hello World" horizontally on a 640 pixel-wide display.

Show TOC