TextSetJustify

Syntax

Success = TextSetJustify(Text, Justify)

Description

Sets the horizontal alignment (justification) of the text within its layout bounds (defined by TextSetWidth()).

Parameters

Text
The handle of the text object to modify.

Justify
The horizontal justification mode constant.

#PG_Text_Justify_Leading   : Aligns text to the leading edge (left for LTR languages). (Default)
#PG_Text_Justify_Trailing  : Aligns text to the trailing edge (right for LTR languages).
#PG_Text_Justify_Center    : Centers text horizontally within the layout bounds.
#PG_Text_Justify_Justified : Justifies text by adjusting spacing between words to fill the layout width (only affects multi-line text).

Return Value

Returns #True if the justification was set successfully, or #False if the handle or justification constant was invalid.

Remarks

This setting takes effect only if a layout width has been specified for the text object using TextSetWidth() or during creation, and the actual text line width is less than the layout width (except for justified text).

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

Global MyText

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
    DrawClear(RGB(240, 240, 240), 1)
    DrawBoxStroke(10,10,200,50,0) ; Draw layout bounds
    DrawTxt(MyText, 10, 10, 0)
EndProcedure

MyWindow = CreateWindow(0, 0, 250, 100, "Text Justification")

If MyWindow
    MyText = CreateText("Centered Text", "Arial", 14)
    TextSetWidth(MyText, 200) ; Set layout width
    TextSetJustify(MyText, #PG_Text_Justify_Center) ; Center horizontally

    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, TextGetJustify, TextSetAlign, TextSetWidth

Supported OS

Windows, Linux