Syntax
Success = WidgetRedraw(Widget, *Rect.RECT=#Null, RedrawFlags=#Null)
Description
Invalidates a specified rectangular area within the widget's bounds, queuing it (and the corresponding area in its parent window) for redrawing during the next rendering cycle. If no rectangle is specified, the widget's entire area is invalidated.
Parameters
Widget
The handle of the ProGUI widget to redraw.
*Rect.RECT (optional)
A pointer to a RECT structure defining the area to invalidate, specified in device-independent pixels (DIPs) relative to the widget's top-left corner (0,0). If #Null, the entire widget area is invalidated.
RedrawFlags (optional)
Additional flags to modify the redraw behavior. Default is #Null.
#PG_Redraw_AllChildren : If the widget contains a layout, this flag ensures all child widgets within that layout are also marked for redraw, regardless of whether they intersect the specified *Rect.
Return Value
Returns #True if the redraw request was successfully queued, or #False if the widget handle was invalid, the widget is hidden/no-draw, or the rectangle dimensions were invalid.
Remarks
This function is the primary way to signal that a widget's visual appearance needs to be updated. It internally calculates the widget's position within the window and calls WindowRedraw() with the appropriate coordinates. Like WindowRedraw(), it's asynchronous. Multiple calls before a render cycle will be combined. Coordinates in the RECT structure are relative to the widget itself.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
Global DrawCount = 0
; Custom draw procedure for our widget
Procedure DrawMyRedrawWidget(Widget, EventType, *EventData.PG_EventDraw, *UserData)
DrawCount + 1
DrawBox(0, 0, *EventData\width, *EventData\height, RGB(200, 200, 255), 1)
Shared MyTextObj
If MyTextObj = 0 : MyTextObj = CreateText("", "Arial", 12) : EndIf
TextSetContent(MyTextObj, "Draw Count: " + Str(DrawCount))
TextSetWidth(MyTextObj, *EventData\width - 10)
TextSetHeight(MyTextObj, *EventData\height - 10)
DrawTxt(MyTextObj, 5, 5, RGB(0,0,0), 1)
EndProcedure
; Event handler to trigger redraw
Procedure ClickToRedrawHandler(Widget, EventType, *EventData.PG_EventMouse, WidgetToRedraw)
If EventType = #PG_Event_MouseLeftButtonDown
Debug "Redrawing target widget..."
WidgetRedraw(WidgetToRedraw)
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 300, 200, "WidgetRedraw Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
LayoutFlexSetDirection(RootLayout, #PG_Flex_Direction_Column)
LayoutSetPadding(RootLayout, 10)
If MyWindow
; The widget that will be redrawn
TargetWidget = CreateWidget(0, 0, 200, 50)
WidgetSetClass(TargetWidget, "target")
WidgetSetMargin(TargetWidget, 5)
AddEventHandler(TargetWidget, #PG_Event_Draw, @DrawMyRedrawWidget())
; A button to trigger the redraw
RedrawButton = CreateWidget(0, 0, 100, 30)
WidgetSetClass(RedrawButton, "button")
WidgetSetMargin(RedrawButton, 5)
AddEventHandler(RedrawButton, #PG_Event_MouseLeftButtonDown, @ClickToRedrawHandler(), TargetWidget)
; (Add drawing handler for RedrawButton if needed)
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WindowRedraw, WidgetUpdate, AddEventHandler, #PG_Event_Draw
Supported OS
Windows, Linux