Syntax
Width.d = TextGetWidth(Text, ReturnLayoutWidth=#False)
Description
Retrieves the calculated width of the text layout in device-independent pixels (DIPs). Optionally, it can return the maximum layout width constraint set for the text object.
Parameters
Text
The handle of the text object whose width is to be retrieved.
ReturnLayoutWidth (optional)
If set to #True, the function returns the maximum layout width set using TextSetWidth() or during creation. If #False (default), returns the actual calculated width of the rendered text (considering wrapping, font size, etc.).
Return Value
Returns the requested width as a floating-point number (Double) in DIPs. Returns 0.0 or #False if the text handle is invalid. If ReturnLayoutWidth is #True and no layout width was set, it may return 0 or a large default value depending on the underlying text engine.
Remarks
The calculated width (`ReturnLayoutWidth = #False`) represents the actual horizontal space occupied by the longest line of text after layout and wrapping. The layout width constraint (`ReturnLayoutWidth = #True`) is the value used for horizontal alignment/justification and trimming calculations.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyText = CreateText("Sample Text", "Arial", 14)
If MyText
CalculatedWidth.d = TextGetWidth(MyText)
Debug "Calculated Text Width (DIPs): " + StrD(CalculatedWidth.d)
TextSetWidth(MyText, 200) ; Set a layout width constraint
LayoutWidth.d = TextGetWidth(MyText, #True)
Debug "Layout Width Constraint (DIPs): " + StrD(LayoutWidth.d) ; Should be 200.0
FreeText(MyText)
EndIf
StopProGUI()
See Also
CreateText, TextSetWidth, TextGetHeight, TextSetHeight
Supported OS
Windows, Linux