Fl_Flowpack: Improve layout.

This commit is contained in:
Jonathan Moore Liles 2013-02-12 16:49:35 -08:00
parent 4f4698a12c
commit 85e225810f
1 changed files with 25 additions and 5 deletions

View File

@ -99,6 +99,9 @@ public:
_max_width = 0; _max_width = 0;
int LW = 0;
int LH = 0;
for ( int i = 0; i < children(); ++i ) for ( int i = 0; i < children(); ++i )
{ {
Fl_Widget *o = child( i ); Fl_Widget *o = child( i );
@ -108,12 +111,28 @@ public:
H = o->h() > H ? o->h() : H; H = o->h() > H ? o->h() : H;
if ( _flow && X + o->w() >= W ) if ( _flow )
{ {
if ( Y + o->h() < H )
{
/* if it'll fit in this column, put it below the previous widget */
X -= LW + _hspacing;
}
else if ( X + o->w() >= W )
{
/* maybe wrap to the next row */
H += o->h();
Y += H + _vspacing; X = 0;
H = o->h(); }
X = 0; else
{
/* otherwise, put it in the next column */
Y = 0;
}
LW = o->w();
LH = o->h();
} }
/* avoid bothering the control with lots of resize() calls */ /* avoid bothering the control with lots of resize() calls */
@ -121,7 +140,8 @@ public:
o->y() == y() + Y ) ) o->y() == y() + Y ) )
o->position( x() + X, y() + Y ); o->position( x() + X, y() + Y );
X += o->w() + _hspacing; Y += LH + _vspacing;
X += LW + _hspacing;
if ( X > _max_width ) if ( X > _max_width )
_max_width = X; _max_width = X;