Syntax
Success = WidgetSetAlign(Widget, AlignFlag)
Description
Sets the alignment property for an individual widget within its parent layout container. Alignment controls how the widget is positioned along the cross-axis of the layout (e.g., vertically in a row, horizontally in a column) relative to other items in the same line or the container itself.
Parameters
Widget
The handle of the ProGUI widget to modify.
AlignFlag
The desired alignment setting. Possible values:
#PG_Widget_Align_Start : Aligns the widget to the start of the cross-axis.
#PG_Widget_Align_Center : Centers the widget along the cross-axis.
#PG_Widget_Align_End : Aligns the widget to the end of the cross-axis.
; Note: A value of 0 or #False might revert to the default alignment (often stretch or start).
Return Value
Returns #True if the alignment was successfully set, or #False if the widget handle or alignment flag was invalid.
Remarks
This function sets the `align-self` property for the widget's corresponding layout item. It overrides the default alignment specified by the parent layout's `AlignItems` (for Flexbox) or `AlignGridItems` (for Grid) properties. Setting this property triggers a layout update.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 200, "Widget Align Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex) ; Use Flex Row layout
LayoutSetPadding(RootLayout, 10)
LayoutFlexSetAlignItems(RootLayout, #PG_Flex_AlignItems_Center) ; Default center alignment for items
If MyWindow
Widget1 = CreateWidget(0, 0, 80, 30)
WidgetSetClass(Widget1, "widget1")
WidgetSetMargin(Widget1, 5)
; Widget1 will use the default center alignment
Widget2 = CreateWidget(0, 0, 80, 50) ; Taller widget
WidgetSetClass(Widget2, "widget2")
WidgetSetMargin(Widget2, 5)
WidgetSetAlign(Widget2, #PG_Widget_Align_Start) ; Override to align at the top
Widget3 = CreateWidget(0, 0, 80, 20) ; Shorter widget
WidgetSetClass(Widget3, "widget3")
WidgetSetMargin(Widget3, 5)
WidgetSetAlign(Widget3, #PG_Widget_Align_End) ; Override to align at the bottom
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WidgetGetAlign, WidgetSetJustify, LayoutFlexSetAlignItems, LayoutGridSetAlignItems
Supported OS
Windows, Linux