Syntax
Success = WidgetSetLayout(Widget, Layout)
Description
Assigns a layout container to a widget, allowing the widget to act as a container for other child widgets.
Parameters
Widget
The handle of the ProGUI widget that will become the container.
Layout
The handle of the layout object (created with CreateLayout()) to assign to the widget.
Return Value
Returns #True if the layout was successfully assigned, or #False if either handle was invalid.
Remarks
This function enables hierarchical layout structures. Widgets added after setting the current layout to the one assigned here (using LayoutSetCurrent()) will become children of this widget's layout. The assigned layout inherits necessary context (like the parent window) from the widget it's assigned to. Setting a layout triggers a layout update.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 300, "Widget Set Layout")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetPadding(RootLayout, 10)
If MyWindow
; Create the container widget
ContainerWidget = CreateWidget(0, 0, 200, 150)
WidgetSetClass(ContainerWidget, "container")
WidgetSetMargin(ContainerWidget, 5)
; Add drawing handler if needed
; Create a new layout (Flex, column)
InnerLayout = CreateLayout(#PG_Layout_Type_Flex)
LayoutFlexSetDirection(InnerLayout, #PG_Flex_Direction_Column)
LayoutSetPadding(InnerLayout, 5)
; Assign the new layout to the container widget
If WidgetSetLayout(ContainerWidget, InnerLayout)
Debug "Inner layout assigned to container widget."
; Add children to the inner layout
LayoutSetCurrent(InnerLayout) ; Target the inner layout
Child1 = CreateWidget(0, 0, 80, 25)
WidgetSetClass(Child1, "child1")
WidgetSetMargin(Child1, 3)
Child2 = CreateWidget(0, 0, 80, 25)
WidgetSetClass(Child2, "child2")
WidgetSetMargin(Child2, 3)
LayoutSetCurrent(RootLayout) ; Restore root layout
EndIf
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WidgetGetLayout, CreateLayout, CreateWidget (with layout flags), LayoutSetCurrent, LayoutPush, LayoutPop
Supported OS
Windows, Linux