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")
If MyWindow
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Grid) ; Set root to grid
; Add HBoxLayout as an item to the RootLayout (which is current)
HBoxContainer = CreateWidget(0, 0, 0, 0)
; Create a horizontal flex layout but don't add widgets to it yet
HBoxLayout = CreateLayout(#PG_Layout_Type_Flex)
LayoutFlexSetDirection(HBoxLayout, #PG_Flex_Direction_Row)
WidgetSetLayout(HBoxContainer, HBoxLayout)
; Explicitly set HBoxLayout as the current layout
LayoutSetCurrent(HBoxLayout)
; These widgets will now be added to HBoxLayout
Button1 = CreateWidget(0, 0, 80, 30)
Button2 = CreateWidget(0, 0, 80, 30)
; Optionally, set back to RootLayout if more widgets are needed there
LayoutSetCurrent(RootLayout)
StatusLabel = CreateWidget(0, 0, 100, 0)
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
CreateLayout, LayoutGetCurrent, LayoutPush, LayoutPop, CreateWidget
Supported OS
Windows, Linux