Syntax
PushedLayout = LayoutPush()
Description
Pushes the currently active layout onto an internal layout stack. This is useful for temporarily changing the current layout (e.g., by calling CreateLayout() or LayoutSetCurrent()) and later restoring the previous layout using LayoutPop().
Parameters
This command takes no parameters.
Return Value
Returns the handle of the layout that was just pushed onto the stack. Returns #Null if no
layout was currently active to push.
Remarks
This function, along with LayoutPop(), provides a stack-based mechanism for managing the current layout, simplifying the construction of nested layout structures. It's an alternative to manually saving and restoring the current layout using LayoutGetCurrent() and LayoutSetCurrent().
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Push/Pop Layout")
If MyWindow
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
LayoutFlexSetDirection(RootLayout, #PG_Flex_Direction_Column)
LayoutSetCurrent(RootLayout) ; Ensure root is current
Debug "Current Layout (Root): " + Str(LayoutGetCurrent())
; Create Widget 1 in RootLayout
Widget1 = CreateWidget(0,0,100,30)
; Push RootLayout onto the stack
LayoutPush()
Debug "Pushed layout onto stack."
; This container widget is added to RootLayout because it was current *before* InnerLayout was created
ContainerWidget = CreateWidget(0,0, 200, 200)
; Create a new layout, it becomes current
InnerLayout = CreateLayout(#PG_Layout_Type_Flex)
LayoutFlexSetDirection(InnerLayout, #PG_Flex_Direction_Row)
WidgetSetLayout(ContainerWidget, InnerLayout)
Debug "Current Layout (Inner): " + Str(LayoutGetCurrent())
; Create Widgets 2 & 3 in InnerLayout
Widget2 = CreateWidget(0,0,50,30)
Widget3 = CreateWidget(0,0,50,30)
; Pop the stack, restoring RootLayout as current
Restored = LayoutPop()
Debug "Popped layout from stack. Restored: " + Str(Restored)
Debug "Current Layout (Restored Root): " + Str(LayoutGetCurrent())
; Create Widget 4 in RootLayout
Widget4 = CreateWidget(0,0,100,30)
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
LayoutPop, LayoutGetCurrent, LayoutSetCurrent, CreateLayout
Supported OS
Windows, Linux