On Thursday, 6 October 2022 at 05:15:08 UTC+1 roger wrote:
I have some code as follows:-
void win2_showChart(Fl_Widget *w, void *data)
{
win2_accountNo_callback(win2,&xNull);
for (int k;k<1000000;k++){;}
win2_tabs->hide();
win2_chart->show();
win2->redraw();
}
win2_accountNo_callback sets a new value for FL_Output, however unless I put in the "timer" to "slow something down ??" it will not display correctly. I thought that's what win2->redraw was supposed to do ?
OK - there's a few things you need to get your head around here. The key point here is that updating the display is largely asynchronous, so calling redraw() does not *do* the redraw, it just tells the rendering system that that object needs to be redrawn next time it is the neighbourhood...
Further, this looks like a callback method?
You do not want to do *anything* time consuming in a callback method if you can avoid it, since the callbacks are inextricably linked to event processing, so any time spent in a callback will inhibit event processing and make the GUI unresponsive. Callbacks need to be quick "in and out" jobs as far as possible, with any heavy lifting deferred (agin, probably
asynchronously) to other processing "elsewhere" in your code.
The *third* observation I'd make is that I'd be quite surprised if adding an empty "for" loop actually introduces a delay - any modern compiler should be optimizing the empty loop away, unless you either have inhibited the optimizer (you might have done) or explicitly tagged the loop volatile (you did not.)
In general, if you mark an object for redraw, then it should be redrawn the next time the display is refreshed; trying to force it to draw "right now" is unlikely to be useful.
What are you trying to achieve? What effect are you seeing that seems wrong?