Stan wrote:
>>      I'd agree -- you only should need to call init_sizes()
>>      after you change the arrangement of the child widgets yourself,
>>      such as with size(), position() or resize().
>>
>>      You shouldn't need to call init_sizes() if the Fl_Group
>>      is resized, it will handle auto-sizing the children automatically
>>      to try to keep their relative size and position arrangement.
> 
> I guess it's the concept of changing things "yourself" that I'm
> trying to get my mind around.  Can I conclude that init_sizes()
> needs to be called (only) after calling resize (or one of its cousins)
> on a group member, from outside the execution context of the group's
> resize method?

Yes, but see below.

> For instance, suppose I've derived MyGroup from Fl_Group,
> and implemented its resize() method.

How did you "implement its resize method" ?

Remember that resize() is a virtual method. If you implement your
own resize() method, then you may still need to call something
like my_group->Fl_Widget::resize() on it to change the group's
coordinates and size. See example below.

> Now, for MyGroup* my_group, my_group->child(0)->size(..)
> should be followed by my_group->init_sizes(), but my_group->resize(..)
> should not be, even though it may do the same thing to child(0).
> 
> Is that about right?

Maybe or not, that depends ;-)

Case 1: if you implemented your own resize() method for MyGroup, and
this resize method _does_ resize all its children, then there is no need
to call init_sizes() at all, because Fl_Group::resize() will never be
executed (if you don't call it from MyGroup::resize()), and therefore
the sizes_ array in Fl_Group will never be used.

Case 2: if you don't implement your own resize() method or if you
call Fl_Group::resize() from your implementation, then Fl_Group's
sizes_ array will be used for resizing the children, and then you
should call init_sizes if/when you (re)arrange the group's children.

Short rule: if you don't implement your own group resize method,
then call init_sizes() whenever you change widget dimensions
within a group, else you shouldn't need init_sizes() at all.

Example:

MyGroup::resize(int X, int Y, int W, int H)
{
   Fl_Widget::resize(X,Y,W,H);  // resize MyGroup [1]

   if (children()>0) {
     for (int i=0; i<children(); i++) {
       child(i)->resize(X+10*i,Y+10*i,10,10); // [2]
     }
   }
}

[1] you could even call Fl_Widget::resize() with different
coordinates and width/height here to move/resize the
group different from what was calculated for the
parent group (X,Y,W,H).

[2] do your own calculations here, but check that all
children remain within the new group boundaries.

Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to