Syntax
Layout = CreateLayout(LayoutType=#PG_Layout_Type_Basic)
Description
Creates a new layout container object. Layouts are used to manage the positioning and sizing of child widgets and other nested layouts. Different layout types provide different arrangement algorithms.
Parameters
LayoutType (optional)
Specifies the layout engine to use for this container.
Default is #PG_Layout_Type_Basic.
#PG_Layout_Type_Basic : Widgets are positioned using explicit coordinates relative to the layout.
#PG_Layout_Type_Flex : Uses a Flexbox model to arrange items. Configure with `LayoutFlexSet...` commands.
#PG_Layout_Type_Grid : Uses a Grid model to arrange items. Configure with `LayoutGridSet...` commands.
Return Value
Returns a handle to the newly created layout object if successful, or #Null on failure.
Remarks
The newly created layout becomes the "current" layout (see LayoutSetCurrent() and LayoutGetCurrent()). Subsequent calls to CreateWidget() will add widgets to this current layout unless changed. Layouts themselves can be added to other layouts by first creating the child layout and then calling WidgetSetLayout() on a container widget (which implicitly adds the layout to the container widget's parent layout). Every window (CreateWindow()) automatically has a root layout created for it.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Layout Example")
If MyWindow
; Get the window's root layout
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex) ; Make root layout Flex
LayoutFlexSetDirection(RootLayout, #PG_Flex_Direction_Column)
LayoutSetPadding(RootLayout, 10)
; Create a container widget and later assign the new grid layout to it
; This widget is added to the RootLayout (the current layout when CreateWidget is called)
GridContainerWidget = CreateWidget(0, 0, #PG_Widget_FitContent, #PG_Widget_FitContent)
WidgetSetMargin(GridContainerWidget, 5)
; Create a new Grid layout
MyGridLayout = CreateLayout(#PG_Layout_Type_Grid)
LayoutGridSetColumn(MyGridLayout, 1, 100) ; Column 1 width 100
LayoutGridSetColumn(MyGridLayout, 2, #PG_Grid_Auto) ; Column 2 auto size
LayoutSetPadding(MyGridLayout, 5)
WidgetSetLayout(GridContainerWidget, MyGridLayout) ; Assign the grid layout
; Now set the current layout to the Grid layout to add widgets *inside* it
LayoutSetCurrent(MyGridLayout)
Label1 = CreateWidget(0, 0, 100, 100)
; ... set label text/class ...
WidgetSetColumnStart(Label1, 1) ; Place in column 1
Input1 = CreateWidget(0, 0, 200, 100)
; ... set input class ...
WidgetSetColumnStart(Input1, 2) ; Place in column 2
; Restore the previous layout (RootLayout) if needed for more widgets outside the grid
; LayoutSetCurrent(RootLayout)
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
LayoutSetType, LayoutSetCurrent, LayoutGetCurrent, LayoutPush, LayoutPop, WidgetSetLayout, CreateWidget
Supported OS
Windows, Linux