Syntax
Success = FreeWidget(Widget)Description
Removes the specified widget from its parent layout and frees all associated resources. The widget will no longer be visible or interactive, and its handle becomes invalid.
Parameters
Widget
The handle of the ProGUI widget to free.
Return Value
Returns #True if the widget was successfully marked for
deletion, or #False if the handle was invalid.
Remarks
This function queues the widget for deletion. The actual removal from
the layout and freeing of memory happens during the layout update cycle.
If the widget had its own layout assigned (WidgetSetLayout()), that layout and all
its contained widgets will also be freed recursively. The
#PG_Event_Destroy event is dispatched to the widget just
before its resources are released, allowing for custom cleanup.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
Global WidgetToFree
; Event handler for button click
Procedure ButtonHandler(Widget, EventType, *EventData, *UserData)
If EventType = #PG_Event_Action
If WidgetToFree
Debug "Freeing the widget..."
FreeWidget(WidgetToFree)
Debug "Widget marked for deletion."
WidgetToFree = #Null ; Clear the global handle
Else
Debug "Widget already freed."
EndIf
EndIf
EndProcedure
; Event handler for the widget being freed
Procedure DestroyHandler(Widget, EventType, *EventData, *UserData)
If EventType = #PG_Event_Destroy
Debug "Widget Destroy event received!"
; Perform any cleanup related to this specific widget here
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 300, 200, "FreeWidget Example", #PG_Window_Default | #PG_Window_LayoutFlex) ; Create with a flex layout
LayoutFlexSetDirection(#Null, #PG_Flex_Direction_Column) ; Set the flex direction of the current layout
LayoutSetPadding(#Null, 10)
If MyWindow
; The widget we will free
WidgetToFree = CreateWidget(0, 0, 200, 50)
WidgetSetClass(WidgetToFree, "status-label") ; Assume skin exists
WidgetSetMargin(WidgetToFree, 5)
AddEventHandler(WidgetToFree, #PG_Event_Destroy, @DestroyHandler())
; Add drawing handler if needed
; A button to trigger freeing the widget
FreeButton = CreateButton(0, 0, 100, 30, "Click to Free!")
WidgetSetMargin(FreeButton, 5)
AddEventHandler(FreeButton, #PG_Event_Action, @ButtonHandler())
; Add drawing handler if needed
WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()See Also
CreateWidget, CreateOsWidget, #PG_Event_Destroy, AddEventHandler
Supported OS
Windows, Linux