LayoutSetType

Syntax

Success = LayoutSetType(Layout, LayoutType, Flags=#Null)

Description

Changes the layout engine type used by the specified layout container. This determines how child widgets and layouts within this container are arranged.

Parameters

Layout
The handle of the layout object whose type is to be changed.

LayoutType
The new layout type constant.

#PG_Layout_Type_Basic : Simple layout based on explicit widget coordinates.
#PG_Layout_Type_Flex  : Flexbox model.
#PG_Layout_Type_Grid  : Grid model.

Flags (optional)
Flags to modify the behavior.

#PG_Layout_NoUpdate : Prevents the layout from automatically recalculating and redrawing after the type change. Use this if making multiple changes before requiring an update.

Return Value

Returns #True if the layout type was successfully changed, or #False if the layout handle or type was invalid.

Remarks

Changing the layout type will likely change the position and size of the child elements within the layout. The layout is automatically updated unless #PG_Layout_NoUpdate is specified.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 300, "Set Layout Type")

If MyWindow
  RootLayout = WindowGetLayout(MyWindow)
  LayoutSetPadding(RootLayout, 10)

  ; Initially, the root layout is Basic (default)
  Debug "Initial Layout Type: " + Str(LayoutGetType(RootLayout))

  ; Add some widgets (their x,y will be used initially)
  Widget1 = CreateWidget(10, 10, 100, 30)
  Widget2 = CreateWidget(120, 10, 100, 30)

  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
  
  Repeat
    If Event = #PB_Event_LeftClick
      ; Change the layout type to Flexbox (row direction)
      Debug "Changing Layout Type to Flex..."
      LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
      LayoutFlexSetDirection(RootLayout, #PG_Flex_Direction_Row)
      LayoutFlexSetJustify(RootLayout, #PG_Flex_Justify_SpaceAround) ; Add some justification
      Debug "New Layout Type: " + Str(LayoutGetType(RootLayout))
    EndIf
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

CreateLayout, LayoutGetType, WindowGetLayout

Supported OS

Windows, Linux