LayoutSetCurrent

Syntax

Success = LayoutSetCurrent(Layout)

Description

Sets the specified layout container as the current layout. Subsequent calls to CreateWidget() will add the new widget to this layout.

Parameters

Layout
The handle of the layout object to set as the current target.

Return Value

Returns #True if the layout handle was valid and successfully set as current. Returns #False otherwise.

Remarks

This function allows explicitly controlling which layout container receives newly created widgets. It's often used in conjunction with LayoutGetCurrent(), LayoutPush(), and LayoutPop() to manage nested layout structures.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 300, "Set Current Layout", #PG_Window_Default | #PG_Window_LayoutGrid) ; Create with a grid layout

If MyWindow
  
  RootLayout = LayoutGetCurrent()
  
  CreateWidget(0, 0, 100, 0) ; Add a widget to the current layout
  
  ; Add HBoxLayout to the current layout
  HBoxContainer = CreateWidget(0, 0, 0, 0, #Null, #PG_Widget_LayoutFlex) ; Create widget with a horizontal flex layout which becomes the current layout
  
  LayoutSetCurrent(RootLayout) ; Explicitly set previous RootLayout as the current layout, LayoutPush() / LayoutPop() could have been used here instead
  
  CreateWidget(0, 0, 100, 0) ; Now add another widget to the root
  
  ; Explicitly set HBoxContainer's layout as the current layout
  LayoutSetCurrent(WidgetGetLayout(HBoxContainer))

  ; These widgets will now be added to HBoxContainer's layout
  Button1 = CreateButton(0, 0, 80, 30, "Button1")
  Button2 = CreateButton(0, 0, 80, 30, "Button2")

  ; Optionally, set back to RootLayout if more widgets are needed there
  LayoutSetCurrent(RootLayout)
  CreateWidget(0, 0, 100, 0)

  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)

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

StopProGUI()

See Also

CreateLayout, LayoutGetCurrent, LayoutPush, LayoutPop, CreateWidget

Supported OS

Windows, Linux