TextSetWidth

Syntax

TextSetWidth(Text, LayoutWidth.d)

Description

Sets the maximum layout width constraint for the specified text object in device-independent pixels (DIPs).

Parameters

Text
The handle of the text object to modify.

LayoutWidth.d
The maximum width in DIPs for the text layout. If the text content exceeds this width, it might wrap or be trimmed depending on the TextSetWrap() and TextSetTrimming() settings. Setting to #Null or 0 removes the width constraint.

Return Value

This function does not return a value.

Remarks

Setting a layout width affects text wrapping, horizontal alignment (TextSetJustify()), and potentially text trimming. It defines the horizontal bounds within which the text will be flowed and positioned.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

Global MyText

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
    DrawClear(RGB(240, 240, 240), 1)
    DrawBoxStroke(10,10,*EventData\width-20,*EventData\height-20,0) ; Show layout bounds
    TextSetWidth(MyText, *EventData\width-20)
    TextSetHeight(MyText, *EventData\height-20)
    DrawTxt(MyText, 10, 10, 0)
EndProcedure

MyWindow = CreateWindow(0, 0, 200, 150, "Text Layout Width")

If MyWindow
    MyText = CreateText("This is a line of text that will wrap because its layout width is constrained.", "Arial", 14)
    
    TextSetWrap(MyText, #PG_Text_Wrap_Wrap) ; Enable word wrapping

    AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
    WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
    Repeat: Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
    FreeText(MyText)
EndIf

StopProGUI()

See Also

CreateText, TextGetWidth, TextSetHeight, TextSetJustify, TextSetWrap, TextSetTrimming

Supported OS

Windows, Linux