WindowSetLayout

Syntax

OldLayout = WindowSetLayout(Window, Layout, LayoutType=#PG_Window_LayoutType_Client)

Description

Replaces or sets the active layout container for a specific area of a window.

Parameters

Window
The handle of the ProGUI window to update.

Layout
The handle to the new layout (created with CreateLayout()) to bind to the window. You can pass #Null to detach the current layout without setting a new one.

LayoutType (optional)
Specifies which specific part of a skinned window the layout should be attached to. This is ignored for standard OS system windows. Default is #PG_Window_LayoutType_Client.

#PG_Window_LayoutType_Client    : Attaches the layout to the window's client area widget. This is the default and most common usage.
#PG_Window_LayoutType_Container : Attaches the layout to the window's outer container widget (spanning the entire window, including custom titlebars).
#PG_Window_LayoutType_Root      : Replaces the absolute root layout of the window itself.

Return Value

Returns the handle to the old layout that was previously attached, or #Null if none existed. Returns #False if the window handle is invalid or the layout is already attached to this target.

Remarks

Normally, ProGUI windows possess a default layout upon creation. For skinned windows (windows created without the #PG_Window_System flag), they automatically construct an internal layout structure consisting of a root layout, a container widget, an optional titlebar, and a client area widget.

By default, WindowSetLayout() attaches your layout to the client area (#PG_Window_LayoutType_Client), which is usually the desired behavior for adding content.

The old layout that is returned is detached but not freed automatically. If the old layout is no longer needed, you must free it manually using FreeLayout() to prevent memory leaks.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

; Create a standard ProGUI window
MyWindow = CreateWindow(0, 0, 500, 400, "WindowSetLayout Example")

If MyWindow
  ; Create a new Flex layout
  MyLayout = CreateLayout(#PG_Layout_Type_Flex)
  LayoutSetPadding(MyLayout, 20)
  LayoutFlexSetDirection(MyLayout, #PG_Flex_Direction_Column)
  LayoutFlexSetAlignItems(MyLayout, #PG_Flex_AlignItems_Center)
  
  ; Swap the default client layout with our new layout
  OldLayout = WindowSetLayout(MyWindow, MyLayout)
  
  ; Free the old detached layout to prevent memory leaks
  If OldLayout
    FreeLayout(OldLayout)
  EndIf

  ; Add a widget to our newly attached layout
  MyButton = CreateWidget(0, 0, 150, 40)
  WidgetSetClass(MyButton, "button") ; Requires a defined "button" skin
  
  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)

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

StopProGUI()

See Also

WindowGetLayout, CreateLayout, WidgetSetLayout, FreeLayout

Supported OS

Windows, Linux