Syntax
Success = WidgetUpdate(Widget)
Description
Forces an update cycle for the specified widget's parent layout (or the widget's own layout if it acts as a container). This involves processing any pending layout item actions (like adding/removing children) and recalculating the layout, followed by redrawing the affected area of the parent window.
Parameters
Widget
The handle of the ProGUI widget whose containing layout needs updating.
Return Value
Returns #True if the update process was successfully initiated, or #False if
the widget handle was invalid or the widget is hidden.
Remarks
This function is useful when changes have been made that affect the layout (e.g., changing widget properties like margins or minimum sizes) and a visual update needs to be triggered manually. It essentially calls `updateLayoutRedraw()` on the relevant layout. If the widget itself has a layout (i.e., it's a container), this function updates the widget's own layout; otherwise, it updates the parent layout that contains the widget.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
; Event handler to change margin and update
Procedure ChangeMarginHandler(Widget, EventType, *EventData, WidgetToUpdate)
If EventType = #PG_Event_MouseLeftButtonUp
NewMargin = Random(20) + 5 ; Random margin between 5 and 25
Debug "Setting margin to: " + Str(NewMargin)
WidgetSetMargin(WidgetToUpdate, NewMargin)
; WidgetUpdate(WidgetToUpdate) ; Not strictly needed as SetMargin calls updateLayoutRedraw
Debug "Layout update triggered by SetMargin."
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 300, 200, "WidgetUpdate Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
LayoutSetPadding(RootLayout, 10)
If MyWindow
; Widget whose margin will change
TargetWidget = CreateWidget(0, 0, 100, 50)
WidgetSetClass(TargetWidget, "target")
WidgetSetMargin(TargetWidget, 5)
; Add drawing handler if needed
; Button to trigger the change
ChangeButton = CreateWidget(0, 0, 100, 30)
WidgetSetClass(ChangeButton, "button")
WidgetSetMargin(ChangeButton, 5)
AddEventHandler(ChangeButton, #PG_Event_MouseLeftButtonUp, @ChangeMarginHandler(), TargetWidget)
; Add drawing handler for button
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WindowUpdate, WidgetRedraw, LayoutSetProperty (and related layout functions), WidgetSetMargin (and related widget property functions)
Supported OS
Windows, Linux