Syntax
Layout = CreateLayout(LayoutType=#PG_Layout_Type_Basic)Description
Creates a new layout container for managing the size and positioning of child widgets. When a new layout is created, it automatically becomes the current active layout, meaning any subsequently created widgets will automatically be inserted into it.
Parameters
LayoutType (optional)
The type of layout engine to use. Default is
#PG_Layout_Type_Basic.
#PG_Layout_Type_Basic : Standard absolute/relative positioning without automatic flow.
#PG_Layout_Type_Flex : A Flexbox-style layout engine for aligning items in rows or columns with wrapping and distribution. Configure with `LayoutFlexSet...` commands.
#PG_Layout_Type_Grid : A Grid layout engine for arranging items in defined columns and rows. Configure with `LayoutGridSet...` commands.
Return Value
Returns a handle to the newly created layout object.
Remarks
A layout container acts as an invisible logical framework. Once created, it handles the sizing, positioning, padding, and automatic overflow scrollbars for all widgets inserted into it.
Because CreateLayout() automatically sets the newly
created layout as the current active layout (equivalent to calling LayoutSetCurrent()), any CreateWidget() calls made immediately
afterward will add widgets into this new layout.
Layouts can be bound to a parent container by passing them to WindowSetLayout() or WidgetSetLayout(). Standalone layouts that are no longer needed should be freed using FreeLayout() to prevent memory leaks (though layouts attached to widgets/windows are freed automatically when the parent is freed).
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "CreateLayout Example")
If MyWindow
; Create a new Flex layout
MyFlexLayout = CreateLayout(#PG_Layout_Type_Flex)
; Configure the layout's properties
LayoutSetPadding(MyFlexLayout, 20)
LayoutFlexSetDirection(MyFlexLayout, #PG_Flex_Direction_Column)
LayoutFlexSetAlignItems(MyFlexLayout, #PG_Flex_AlignItems_Center)
; Attach the new layout to the window's client area
OldLayout = WindowSetLayout(MyWindow, MyFlexLayout)
If OldLayout : FreeLayout(OldLayout) : EndIf
; Because CreateLayout automatically made MyFlexLayout the current active layout,
; these widgets will be inserted directly into it.
Btn1 = CreateButton(0, 0, 150, 40, "Button 1")
WidgetSetMarginBottom(Btn1, 10)
Btn2 = CreateButton(0, 0, 150, 40, "Button 2")
WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()See Also
FreeLayout, LayoutSetType, LayoutSetCurrent, WindowSetLayout, WidgetSetLayout, Layout Management Overview
Supported OS
Windows, Linux