LayoutPop

Syntax

RestoredLayout = LayoutPop()

Description

Pops the most recently pushed layout from the internal layout stack and sets it as the current layout. This is used to restore a previous layout context after using LayoutPush().

Parameters

This command takes no parameters.

Return Value

Returns the handle of the layout that was restored as the current layout. Returns #Null if the layout stack was empty.

Remarks

This function complements LayoutPush(), providing a stack-based mechanism for managing the current layout context, which simplifies building nested UIs. If the stack is empty when `LayoutPop()` is called, the current layout remains unchanged and #Null is returned.

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

LayoutPush, LayoutGetCurrent, LayoutSetCurrent, CreateLayout

Supported OS

Windows, Linux