Stan wrote:
> Greg Ercolano wrote:
>> This is how I visualize it:
>>
>> init_sizes() and Fl_Group's default resize behavior
>> work together; init_sizes() "snapshots" the widget layout,
>> 'caching' all the children's new positions in an internal array
>> so that later, when the group is resized,
This is only "half way" right. init_sizes() does only _remove_
that cache (sizes_ array), but does _not_ create a snapshot
_when_ it is called. Once it is called, all updates of widget
positions and sizes will _not_ be registered, until the next
resize() method will be called.
See src/Fl_Group.cxx:
Fl_Group::init_sizes() removes the sizes_ array (that's the
full method code):
void Fl_Group::init_sizes() {
delete[] sizes_; sizes_ = 0;
}
Fl_Group::resize() calls Fl_Group::sizes():
void Fl_Group::resize(int X, int Y, int W, int H) {
...
} else if (children_) {
short* p = sizes();
...
}
Fl_Group::sizes() allocates and returns a new sizes_ array, if
it is not yet allocated:
short* Fl_Group::sizes() {
if (!sizes_) {
short* p = sizes_ = new short[4*(children_+2)];
...
}
>> Fl_Group's scaling
>> algorithm can use those cached values to scale the widget's
>> positions up and down, without accumulating precision loss.
True; after the first resize() has been called.
> That's a nice mental model, thanks. Unfortunately, actual
> behavior doesn't seem to match it. At least not to me :)
> For instance, look at this little demo. I'd have thought
> that after moving the boxes apart in the program (without
> taking a new snapshot) resizing the window would be based
> on the prior coordinates.
No, see above. The coordinates, when you resize() the window
for the first time.
> But that doesn't seem to be the
> case. Am I missing something?
>
> #include <FL/Fl_Double_Window.H>
> #include <FL/Fl_Box.H>
> #include <FL/Fl.H>
>
> class DBox : public Fl_Box {
> public:
> DBox(int x, int y, int w, int h, char const* label = 0)
> : Fl_Box(x, y, w, h, label)
> {
> box(FL_DOWN_BOX);
> }
> };
>
> int main()
> {
> Fl_Double_Window win(200, 200);
>
> DBox* bx1 = new DBox(50, 50, 50, 50);
> DBox* bx2 = new DBox(100, 50, 50, 50);
> DBox* bx3 = new DBox(50, 100, 50, 50);
> DBox* bx4 = new DBox(100, 100, 50, 50);
>
> win.end();
> win.resizable(&win);
> win.show();
>
> bx1->position(bx1->x() - 10, bx1->y() - 10);
> bx2->position(bx2->x() + 10, bx2->y() - 10);
> bx3->position(bx3->x() - 10, bx3->y() + 10);
> bx4->position(bx4->x() + 10, bx4->y() + 10);
>
> // It doesn't seem to matter whether or not
> // init_sizes is called here.
> // win.init_sizes();
>
> return Fl::run();
> }
No resizing happens, until the user gets control, and there
is no sizes_ array (cache, snapshot), until that happens for
the first time.
Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk