diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-10-06 18:21:25 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-10-06 18:21:25 +0000 |
| commit | f9039b2ae21988783feae9b362818e7923e82d14 (patch) | |
| tree | 6d6fe3679d73448758f9794e7d4d4f6b22a4adad /src/Fl_Pack.cxx | |
| parent | 67e89232f9ba067825a158734a09e0fa21aacbe3 (diff) | |
Initial revision
git-svn-id: file:///fltk/svn/fltk/trunk@2 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Pack.cxx')
| -rw-r--r-- | src/Fl_Pack.cxx | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/Fl_Pack.cxx b/src/Fl_Pack.cxx new file mode 100644 index 000000000..c236f29c6 --- /dev/null +++ b/src/Fl_Pack.cxx @@ -0,0 +1,78 @@ +// Fl_Pack.C + +// Based on code by Curtis Edwards +// Group that compresses all it's children together and resizes to surround +// them on each redraw (only if box() is zero) +// Bugs: ? + +#include <FL/Fl.H> +#include <FL/Fl_Pack.H> +#include <FL/fl_draw.H> + +Fl_Pack::Fl_Pack(int x,int y,int w ,int h,const char *l) +: Fl_Group(x, y, w, h, l) { + resizable(0); + spacing_ = 0; + // type(VERTICAL); // already set like this +} + +void Fl_Pack::draw() { + int tx = x()+Fl::box_dx(box()); + int ty = y()+Fl::box_dy(box()); + int tw = w()-Fl::box_dw(box()); + int th = h()-Fl::box_dh(box()); + int current_position = horizontal() ? tx : ty; + int maximum_position = current_position; + uchar d = damage(); + Fl_Widget*const* a = array(); + for (int i = children(); i--;) { + Fl_Widget* o = *a++; + int X,Y,W,H; + if (horizontal()) { + X = current_position; + W = o->w(); + Y = ty; + H = th; + } else { + X = tx; + W = tw; + Y = current_position; + H = o->h(); + } + if (spacing_ && current_position>maximum_position && + (X != o->x() || Y != o->y() || d&128)) { + fl_color(color()); + if (horizontal()) + fl_rectf(maximum_position, ty, spacing_, th); + else + fl_rectf(tx, maximum_position, tw, spacing_); + } + if (X != o->x() || Y != o->y() || W != o->w() || H != o->h()) { + o->resize(X,Y,W,H); + o->clear_damage(~0); + } + if (d&128) draw_child(*o); else update_child(*o); + // child's draw() can change it's size, so use new size: + current_position += (horizontal() ? o->w() : o->h()); + if (current_position > maximum_position) + maximum_position = current_position; + current_position += spacing_; + } + if (horizontal()) { + if (maximum_position < tx+tw) { + fl_color(color()); + fl_rectf(maximum_position, ty, tx+tw-maximum_position, th); + } + tw = maximum_position-tx; + } else { + if (maximum_position < ty+th) { + fl_color(color()); + fl_rectf(tx, maximum_position, tw, ty+th-maximum_position); + } + th = maximum_position-ty; + } + tw += Fl::box_dw(box()); if (tw <= 0) tw = 1; + th += Fl::box_dh(box()); if (th <= 0) th = 1; + if (tw != w() || th != h()) {Fl_Widget::resize(x(),y(),tw,th); d = 128;} + if (d&128) draw_box(); +} |
