Syntax
Success = WidgetSetJustify(Widget, JustifyFlag)
Description
Sets the justification property for an individual widget within its parent layout container. Justification controls how the widget is positioned along the main-axis of the layout (e.g., horizontally in a row, vertically in a column) when there is extra space in the area allocated to the widget by the layout engine.
Parameters
Widget
The handle of the ProGUI widget to modify.
JustifyFlag
The desired justification setting. Possible values:
#PG_Widget_Justify_Start : Aligns the widget to the start of its allocated space on the main-axis. (Default)
#PG_Widget_Justify_Center : Centers the widget within its allocated space on the main-axis.
#PG_Widget_Justify_End : Aligns the widget to the end of its allocated space on the main-axis.
; Note: A value of 0 or #False reverts to the default justification (start).
Return Value
Returns #True if the justification was successfully set, or #False if the
widget handle or justification flag was invalid.
Remarks
This function sets the `justify-self` property for the widget's corresponding layout item. It overrides the default justification specified by the parent layout's `JustifyItems` (for Grid) property. It's most noticeable in Grid layouts when a widget is smaller than its grid cell. Setting this property triggers a layout update.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyWindow = CreateWindow(0, 0, 300, 150, "Widget Justify Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Grid) ; Use Grid layout
LayoutSetPadding(RootLayout, 10)
LayoutGridSetGapSize(RootLayout, 10)
; Define 3 columns and one row set to auto
LayoutGridSetColumn(RootLayout, 1, #PG_Grid_Auto)
LayoutGridSetColumn(RootLayout, 2, #PG_Grid_Auto)
LayoutGridSetColumn(RootLayout, 3, #PG_Grid_Auto)
LayoutGridSetRow(RootLayout, 1, #PG_Grid_Auto)
; LayoutGridSetJustifyItems(RootLayout, #PG_Grid_JustifyItems_Center) ; Default justify for items in cells
If MyWindow
; Widget 1 - Default (Start) or Centered if layout set
Widget1 = CreateWidget(0, 0, 50, 30)
WidgetSetClass(Widget1, "cell1")
WidgetSetColumnStart(Widget1, 1) ; Place in col 1
; Widget 2 - Justified to Center
Widget2 = CreateWidget(0, 0, 50, 30)
WidgetSetClass(Widget2, "cell2")
WidgetSetColumnStart(Widget2, 2) ; Place in col 2
WidgetSetJustify(Widget2, #PG_Widget_Justify_Center)
; Widget 3 - Justified to End
Widget3 = CreateWidget(0, 0, 50, 30)
WidgetSetClass(Widget3, "cell3")
WidgetSetColumnStart(Widget3, 3) ; Place in col 3
WidgetSetJustify(Widget3, #PG_Widget_Justify_End)
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WidgetGetJustify, WidgetSetAlign, LayoutGridSetJustifyItems
Supported OS
Windows, Linux