On 03/05/13 11:48, Howard Rubin wrote:
> Hi All,
> 
> I need to make an Fl_Tree_Item visible in an Fl_Tree during 
> initialization, but it doesn't seem to work.
> 
> How can I make it work?

        I believe the issue here is the widget calculates
        the positions of all the items on the fly when the widget
        is actually rendered on the screen.

        And at the point in the code where you're calling show_item_middle(),
        the widget (and window) hasn't actually been drawn yet.
        w->show() just /schedules/ the window to be shown, but doesn't
        actually draw it until the Fl::run() loop has gotten some cpu.

        I found that if I add the following single line just after
        your call to w->show(), it works correctly (on linux at least):

----
     w->end();
     w->show();

     while ( Fl::wait(0.5) ) { }        // <-- ADD THIS ONE LINE

     tree->show_item_middle(p007);
----

        I'm not sure if that's a guaranteed solution, though it works
        for me in the few times I tested it.

        What you really want is to keep calling Fl::wait() in a loop
        until the window has actually been mapped to the screen (drawn)..
        but offhand, not sure if FLTK provides a method to detect this.

        One sure way would be to derive your own class from Fl_Window
        and make your own draw() method that sets a flag that you can
        then poll for in the above loop. I'm pretty sure that would work,
        but it seems like the kind of thing FLTK would have built in.

        I know shown() and visible() can't be used for this..
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to