WindowUpdate

Syntax

Success = WindowUpdate(Window)

Description

Forces an immediate update cycle for the specified window (or all windows if `Window` is `#Null`). This involves processing any pending layout changes and redrawing the entire window.

Parameters

Window
The handle of the ProGUI window to update. If set to #Null or 0, potentially updates all managed windows (behavior might depend on internal implementation, primarily signals the render thread to process updates for all windows).

Return Value

Returns #True if the update signal was successfully sent. (Note: The function itself doesn't return `#False` in the provided code, implying it always succeeds if the process is running).

Remarks

This function is typically used after making significant changes to a window's layout or content outside of normal event handling, or when needing to ensure the window reflects the latest state immediately. It internally signals the render/animation thread, calls `updateLayout()` on the window's root layout, and then calls `WindowRedraw()` for the entire window. Using `WindowUpdate(0)` signals the animation thread to update all windows it manages.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

Structure WindowData
  Layout.i
EndStructure

; Event handler to trigger the update after animation ends
Procedure DelayedUpdateHandler(Window, EventType, *EventData.PG_EventAnimate, *UserData.WindowData)
  If EventType = #PG_Event_Animate And *EventData\state = #PG_Event_Animate_End
    Debug "Animation finished, changing padding and updating window..."
    LayoutSetPadding(*UserData\Layout, 50)
    WindowUpdate(Window) ; Force the update
    Debug "Update complete."
  EndIf
EndProcedure

MyWindow = CreateWindow(0, 0, 400, 300, "Update Example")
MyWindowData.WindowData\Layout = WindowGetLayout(MyWindow)
LayoutSetPadding(MyWindowData\Layout, 10)

MyWidget = CreateWidget(0, 0, 100, 30)
WidgetSetClass(MyWidget, "my-button") ; Assume skin exists

If MyWindow
  AddEventHandler(MyWindow, #PG_Event_Animate, @DelayedUpdateHandler(), @MyWindowData)
  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  Debug "Window shown, waiting 3 seconds via animation before updating padding..."
  ; Start a 3-second animation. When it ends, the handler will change padding and update.
  StartAnimation(MyWindow, 1, 3000) ; ID 1, Duration 3000ms

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

StopProGUI()

See Also

WindowRedraw, WidgetUpdate, LayoutSetProperty (and related layout functions), StartAnimation, AddEventHandler

Supported OS

Windows, Linux