WidgetSetJustify

Syntax

Success = WidgetSetJustify(Widget, Justify)

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.

Justify
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", #PG_Window_Default | #PG_Window_LayoutGrid) ; Use a grid layout
LayoutSetPadding(#Null, 10) ; Set the current layout padding
LayoutGridSetGapSize(#Null, 10)

; Define 3 columns and one row set to auto
LayoutGridSetColumn(#Null, 1, #PG_Grid_Auto)
LayoutGridSetColumn(#Null, 2, #PG_Grid_Auto)
LayoutGridSetColumn(#Null, 3, #PG_Grid_Auto)
LayoutGridSetRow(#Null, 1, #PG_Grid_Auto)
; LayoutGridSetJustifyItems(#Null, #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)

  ; Widget 2 - Justified to Center
  Widget2 = CreateWidget(0, 0, 50, 30)
  WidgetSetJustify(Widget2, #PG_Widget_Justify_Center)

  ; Widget 3 - Justified to End
  Widget3 = CreateWidget(0, 0, 50, 30)
  WidgetSetJustify(Widget3, #PG_Widget_Justify_End)

  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

WidgetGetJustify, WidgetSetAlign, LayoutGridSetJustifyItems

Supported OS

Windows, Linux