Here are some general widget-building tips (in no particular order):
- Never call
PgSetRegion().
- Never call
PtDamageWidget()
from a Draw method.
- Never call Pg... functions from anywhere except the
Draw method.
- You don't need to call
PtDamageWidget()
after calling
PtRealizeWidget().
- In the modify functions, don't call the widget's Extent
method directly. Instead, set Pt_WIDGET_RESIZE
in the widget's
Pt_ARG_FLAGS
resource; the widget
library will calculate the widget's extent and perform any visual cleanup
at the appropriate time.
- If you must calculate the extent immediately, call
PtExtentWidget(),
not your widget's Extent method.
- Use
PtSetResources()
to set the resources of subordinate (procreated) widgets.
- Avoid calling
PgFlush()
— the library will call it automatically when required.
- Never call
PtBkgdHandlerProcess()
from a Draw method.
- It's generally best to create subordinate children in your Defaults
method; this way they can be modified as needed via resources
before being realized. Another upside to this is that the widgets
exist at the time the parent is being realized.
When creating the widgets in methods from Initialization to Connect,
the widgets don't exist at the time of realization and may be skipped.
In this case, you need to have a Realized method in which
you realize the children you want visible.
It's also important to have an Unrealized method in which you
destroy the subordinates or you must check to make sure you
don't already have the subordinates in your Initialization method.
Failing to do either of these will likely produce a memory leak.
- If you have an Extent method, it must actually calculate
the extent of the widget. It's a fairly common mistake to
do lots of dimension, layout, and area calculations and then
forget to actually set the widget's extent. Setting the
extent is usually accomplished via calling:
PtSuperClassExtent( PtBasic "or another superclass", widget);
- If your widget's subordinate children aren't being displayed,
check the widget's resize policy (Pt_ARG_RESIZE_FLAGS).
This resource indicates whether or not the widget's size is adjusted
based on the size and location of its children.
- If you have a Draw method defined, make sure you call
PtClipRemove() if you called PtClipAdd()
earlier in the function.
Don't adjust the draw offset via PgSetTranslation() because the
translation is already set up before your Draw function is
called. If you really do want to change the translation, change
it back before exiting your Draw method.