Oh! I was mid-reply, and I see Albrecht has already said most of what I was
going to say...
> So it appears that when a previous button in the group is removed, the
> button's menu position doesn't get updated.
As Albrecht said, the way Fl_Pack behaves in practice is probably not what you
want for your use case.
I have to confess I don't much care for Fl_Pack in general; every time I tried
to use it, I ended up in difficulties.
Albrecht suggests deriving your own container from Fl_Group - this is probably
the best bet; looks like more work initially but in practice it will be easier
as it gives you so much more control over the way your widgets are positioned,
sized and redrawn...
Albrecht also suggests a workaround based on timers. I think this might work
out pretty well, though I'd consider having my own derived Fl_Pack (or similar
container widget) that, in its derived draw() method, sets a flag to tell
whether the draw has actually been enacted (and hence the sizes properly
recalculated) and have that flag cleared down by the callback that triggers the
timer.
The timer can then "poll" until it sees that the widget has been drawn (the
flag is re-set) and thence that the sizes ought to be correct, for popping up
the menus now...
Well, something like that...
Also, some entirely spurious critique of the example code, for no other reason
than I was part way through rewriting it anyway...
> static Fl_Font LFONT = FL_BOLD;
Would be better to say:
static Fl_Font LFONT = FL_HELVETICA | FL_BOLD;
Which is actually the same thing, but makes it explicit: It is (kinda) just
chance that FL_BOLD on its own works (since FL_HELV... == 0). Really it is
meant as a "modifier", not a name in its own right!
> class Sbut : public Fl_Menu_Button
> {
> public:
> Sbut (int i);
> ~Sbut ();
>
> static void onButton ( Fl_Widget* w, void* v);
> int handle ( int event );
> int i() { return _i; }
>
> int _i;
>/// char* _cstr; // not really needed
> };
> //cccccccccccccccccccccccccc
> Sbut::Sbut (int id )
> : Fl_Menu_Button( 0, 0, 100, 50)
> {
> // cout << "Sbut(s) 0: " << id << endl;
> _i = idx;
> callback(onButton);
> //_cstr = new char[sizeof(int)]; // not needed, and maybe too small
> anyway?
char _cstr[16]; // use a stack automatic temp instead, cheaper than
calling new
> sprintf(_cstr, "%i", id);
> // label(_cstr);
copy_label(_cstr); // use copy_label so the widget manages the label
string for you
> //cccccccccccccccccccccccccc
> Sbut::~Sbut ()
> {
> // delete _cstr;
> }
>
> //***********************
> int main (int argc, char **argv)
> {
> WIN->end();
> // WIN->resizable(G1);
// With a pack, it may be that...
WIN->resizable(WIN); // might work out better...
// Passing argc, argv to show() ensures that fltk picks up
// the system default settings... Useful on some host systems.
> WIN->show(argc, argv);
> return Fl::run();
> }
Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14
3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk