FLTK logo

[fltk.general] Re: How do I do this properly

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: How do I do this properly Ian MacArthur Oct 06, 2022  
 
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?

 

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/ace854b9-3599-4b18-b16f-32027cede3b9n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.