customkeyfocus.C
's
custom widget's appearance changes when it gains or
loses keyboard input focus, and in response to
“r”, “g”, and “b” keys.
This means that it's necessary to redraw the widget when any
of these events occur.
It's possible to perform the necessary work and immediately call
do_draw
(), directly.
customkeyfocus.C
gives an example of a better
way to do this, by calling
schedule_redraw
().
schedule_redraw
() arranges for a subsequent
call to do_draw
() to take place; but also
does a few things that produce a better result:
schedule_redraw
() quietly does nothing
at all if the widget is not visible, and nothing needs
to be redrawn.
This can't happen in
customkeyfocus.C
because all events that
result in an explicit redrawing can only occur while the widget is busy.
Actual redrawing is a low-priority task, done only when there's nothing more urgent to do. The more urgent tasks are: handling display server messages; adding or creating new widgets; moving them around for one reason, or another. It's better to wait until all of this is done in order to avoid needlessly redrawing the same widgets after every little change. It's more efficient to postpone the drawing until the dust settles.
schedule_redraw
() quietly does nothing
if it gets called a second time before the widget gets
redrawn. That's the flip side of the coin.
A custom widget only needs to use
schedule_redraw
() to indicate that it needs
to be redrawn. Multiple calls to
schedule_redraw
result in
only one subsequent execution of do_draw
().