WidgetUpdate

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 and a visual update needs to be triggered manually. 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)
  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 automatically updates
  Debug "Layout update triggered by SetMargin."
EndProcedure

MyWindow = CreateWindow(0, 0, 300, 200, "WidgetUpdate Example", #PG_Window_Default | #PG_Window_LayoutFlex) ; Use a flex layout
LayoutSetPadding(#Null, 10) ; Set the current layout padding

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 = CreateButton(0, 0, 100, 30, "Click me!")
  WidgetSetMargin(ChangeButton, 5)
  AddEventHandler(ChangeButton, #PG_Event_Action, @ChangeMarginHandler(), TargetWidget)

  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)

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

StopProGUI()

See Also

WindowUpdate, WidgetRedraw, WidgetSetMargin (and related widget property functions)

Supported OS

Windows, Linux