LayoutPush

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", #PG_Window_Default | #PG_Window_LayoutFlex) ; Create with a flex layout

If MyWindow
  LayoutFlexSetDirection(#Null, #PG_Flex_Direction_Column) ; Set the current flex layout direction
  
  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
  ContainerWidget = CreateWidget(0, 0, 200, 200, #Null, #PG_Widget_LayoutFlex) ; Create the widget with a flex layout, it becomes current

  Debug "Current Layout (Inner): " + Str(LayoutGetCurrent())

  ; Create Widgets 2 & 3 in the ContainerWidget layout
  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_WindowShow_ScreenCentered)

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

StopProGUI()

See Also

LayoutPop, LayoutGetCurrent, LayoutSetCurrent, CreateLayout

Supported OS

Windows, Linux