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)
Static 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)
Debug "Redrawing target widget..."
WidgetRedraw(WidgetToRedraw)
EndProcedure
MyWindow = CreateWindow(0, 0, 300, 200, "WidgetRedraw Example", #PG_Window_Default | #PG_Window_LayoutFlex) ; Create with a flex layout
LayoutFlexSetDirection(#Null, #PG_Flex_Direction_Column) ; Set the current flex layout direction
LayoutSetPadding(#Null, 10)
If MyWindow
; The widget that will be redrawn
TargetWidget = CreateWidget(0, 0, 200, 50)
WidgetSetClass(TargetWidget, "target")
WidgetSetMargin(TargetWidget, 5)
WidgetSetMinHeight(TargetWidget, 30)
AddEventHandler(TargetWidget, #PG_Event_Draw, @DrawMyRedrawWidget())
; A button to trigger the redraw
RedrawButton = CreateButton(0, 0, 100, 30, "Click me!")
WidgetSetMargin(RedrawButton, 5)
AddEventHandler(RedrawButton, #PG_Event_Action, @ClickToRedrawHandler(), TargetWidget)
WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()See Also
WindowRedraw, WidgetUpdate, AddEventHandler, #PG_Event_Draw
Supported OS
Windows, Linux