Hi,
Thank you very much for explaining the problem fully. I really appreciate that 
you took the time to analyze it, make suggestions, and even play with my code.

You have really impressed me with the quality of help available on the fltk 
forum.

Thanks again,
Marty



>
> > Yep, this was suggested as a workaround only, either to see how it
> > can be done (just for learning), or if one really wants to use
> > Fl_Pack. Deriving from Fl_Pack (as I assume you meant above) for
> > another container widget and do the polling makes things even worse,
> > but I assume that you only wrote it for the same reasons as I did.
>
> Yes, indeed.
> I think the better thing is to make your own container based on Fl_Group, 
> since that gives more control over how the "packed" widgets will finally be 
> drawn anyway...
>
>
> Also, more or less as an aside, I think your (Albrecht's) analysis of how 
> Fl_Pack is "causing" this issue is correct - since I was already poking at 
> marty's code, I tweaked it to use a timer as you had suggested (only for the 
> purposes of experiment of course!) and the code now "works as expecetd"...
>
> ----------
>
> // marty - button add example
>
> #include <iostream>
> #include <string>
> #include <cstdio>
> #include <cstdlib>
>
> #include <FL/Fl.H>
> #include <FL/Fl_Box.H>
> #include <FL/Fl_Menu_Button.H>
> #include <FL/Fl_Menu_Item.H>
> #include <FL/Fl_Pack.H>
> #include <FL/Fl_Window.H>
>
> using std::cout;
> using std::endl;
> using std::string;
>
> static Fl_Pack* G1;
> static Fl_Window* WIN;
>
> static int idx = 0;
>
> static Fl_Color LBG = FL_DARK_BLUE;
> static Fl_Color LFG = FL_WHITE;
> static Fl_Color LSC = FL_BLUE;;
> static Fl_Color LTC = FL_WHITE;
> static Fl_Font  LFONT = (FL_HELVETICA | FL_BOLD);
> static Fl_Fontsize FSIZE = 20;
> static int LSPC = 5;
>
> enum eop { DEL=-1, ADD=1 };
>
> class Sbut  : public Fl_Menu_Button
> {
> public:
>     Sbut (int i);
>
>     static void onButton ( Fl_Widget* w, void* v);
>     int handle ( int event );
>     int i() { return _i; }
>
>     int _i;
> };
>
> //ffffffffffffffffffffffffffff
> void clearTo ( int idx )
> {
>     cout << "clearto " << idx << ": ";
>     Fl_Widget* w;
>
>     int last = G1->children()-1;
>     if ( last > idx )
>       cout << " removing ";
>     {
>       // remove last to idx
>       for ( int i=last; i>-1; i-- )
>       {
>           if ( i != idx )
>           {
>             cout <<  i << " ";
>             w = G1->child(i);
>             G1->remove(w);
>             delete w;
>           }
>       }
>     }
>     WIN->redraw();
>     cout << endl;
> }
>
> //////////////////////////////
> static void pop_on_timeout(void *v)
> {
>     Sbut* sb = (Sbut*)v;
>     WIN->redraw();
>     cout << "pop_on_timeout: popping menu" << endl;
>     sb->popup();
> }
>
> //hhhhhhhhhhhhhhhhhhhhhhhhhhhh
> void onMenu (Fl_Widget* w, void* v)
> {
>     eop op = (eop)fl_intptr_t(v);
>     Sbut* sb;
>
>     if ( op == ADD )
>     {
>         cout << "onMenu: add" << endl;
>         sb = new Sbut(idx);
>         G1->add(sb);
>         idx++;
>         Fl::add_timeout(0.2, pop_on_timeout, (void*)sb);
>     }
>     else if ( op == DEL )
>     {
>         cout << "onMenu 2: deleting" << endl;
>         int i = G1->find(w);
>         clearTo(i);
>         sb = (Sbut*)G1->child(0);
>         Fl::add_timeout(0.2, pop_on_timeout, (void*)sb);
>     }
> }
>
> //mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
> Fl_Menu_Item xMenu[] = {
>     {"add button to end, and popup menu", 0, onMenu, (void*)ADD},
>     {"delete other buttons, and popup menu", 0, onMenu, (void*)DEL},
>     {0}
> };
>
>
> //cccccccccccccccccccccccccc
> Sbut::Sbut (int id )
>     : Fl_Menu_Button( 0, 0, 100, 50)
> {
> //    cout << "Sbut(s) 0: " << id << endl;
>     _i = idx;
>     callback(onButton);
>     char _cstr[16];
>     sprintf(_cstr, "%i", id);
>     copy_label(_cstr);
> //    cout << "label = " << label() << endl;
>     color( LBG, LSC);
>     labelcolor(LFG);
>     labelfont(LFONT);
>     labelsize(FSIZE);
>     menu(xMenu);
>     if ( menu() )
>     {
>         Fl_Menu_Item* mi; // non-const pointer
>         mi = (Fl_Menu_Item*)menu();
>         int sz = mi->size();
>         for ( int j=0; j<sz; j++ )
>         {
>             // cout << "set: " << j << endl;
>             color(LBG, LSC);
>             mi->labelsize(FSIZE);
>             mi->labelfont(LFONT);
>             mi->labelcolor(LFG);
>             mi = mi->next();
>         }
>     }
> }
>
> //hhhhhhhhhhhhhhhhhhhhhhhhhH
> int Sbut::handle ( int event )
> {
>     if ( event == FL_PUSH )
>     {
>       cout << "Sbut handle 1: PUSH " << endl;
>       do_callback();
>       return 1;
>     }
>     return 0;
> }
>
> //hhhhhhhhhhhhhhhhhhhhhhhhhH
> void Sbut::onButton ( Fl_Widget* w, void* v)
> {
>     int i = G1->find(w);
>     cout << "Sbut onButton 0: " << i << endl;
>     Sbut* sb = (Sbut*)w;
>     sb->popup();
> }
>
> //***********************
> int main (int argc, char **argv)
> {
>     Sbut* sb;
>     WIN = new Fl_Window(0, 0, 200, 300);
>     G1 = new Fl_Pack(0, 0, 150, 150);
>     G1->begin();
>     for ( int i=0; i<5; i++ )
>     {
>         sb = new Sbut(i);
>         idx++;
>     }
>     G1->end();
>     WIN->end();
> //    WIN->resizable(G1);
>     WIN->resizable(WIN);
>     WIN->show(argc, argv);
>     return Fl::run();
> }
>
> /* end of file */
>
>

_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to