WidgetGetLayout

Syntax

Layout = WidgetGetLayout(Widget)

Description

Retrieves the handle to the layout container directly associated with (contained within) the specified widget, if one exists.

Parameters

Widget
The handle of the ProGUI widget whose associated layout is to be retrieved.

Return Value

Returns the handle to the layout object associated with the widget if one was assigned using WidgetSetLayout() or during creation with flags like #PG_Widget_LayoutFlex. Returns #Null or #False if the widget handle is invalid or if no layout is directly associated with this widget.

Remarks

Widgets can act as containers themselves by having a layout assigned to them. This function allows you to access that specific layout to add child widgets or modify its properties. To get the layout that *contains* the widget, you would typically access the parent layout structure, often via the widget's `parentLayout` pointer internally or by navigating the layout hierarchy.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 300, "Widget Layout Example")
RootLayout = WindowGetLayout(MyWindow)

If MyWindow
  ; Create a container widget with an automatic Flex layout
  ContainerWidget = CreateWidget(0, 0, 200, 150, #Null, #PG_Widget_LayoutFlex)
  WidgetSetClass(ContainerWidget, "container")
  WidgetSetMargin(ContainerWidget, 10)
  ; Add drawing handler for container if needed

  ; Get the layout *inside* the container widget
  InnerLayout = WidgetGetLayout(ContainerWidget)
  If InnerLayout
    Debug "Got inner layout handle: " + Str(InnerLayout)
    LayoutSetPadding(InnerLayout, 5) ; Modify the inner layout

    ; Add a child widget to the inner layout
    LayoutSetCurrent(InnerLayout) ; Make the inner layout the target for AddWidget
    ChildWidget = CreateWidget(0, 0, 80, 25)
    WidgetSetClass(ChildWidget, "button")
    WidgetSetMargin(ChildWidget, 5)
    ; Add drawing handler for child if needed

    LayoutSetCurrent(RootLayout) ; Restore the root layout as current
  Else
    Debug "Widget does not have an associated layout."
  EndIf

  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

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

StopProGUI()

See Also

WidgetSetLayout, CreateWidget (with layout flags), WindowGetLayout, LayoutSetCurrent

Supported OS

Windows, Linux