DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2639
Version: 1.3-current


Fl_Pack resizes hidden widgets, which it doesn't
touch when visible:

  The tiny example program illustrates the point:

  * resize the window back and forth and both "Group 1" and
    "Group 2" keep their heights. OK here.
  * With a small window, hide "Group 2" and resize to a big
    window, then show "Group 2". It grew while hidden!?

This bug makes it hard to find a way to code a hideable UI panel.
There're workarounds but they're not easy to find as the docs
don't shed light on it.

  Workaround examples:

  1) remove Group2 after hiding, re-insert on show.
  2) resize Group2 to 0,0 upon hide, then resize again upon show.

It'd be great to have a simple and obvious way to do it.


Link: http://www.fltk.org/str.php?L2639
Version: 1.3-current
#include <stdio.h>
#include <stdlib.h>

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Pack.H>

Fl_Pack *p1;
Fl_Group *g1, *g2, *g3;

////////////////////////////////////////////////////////////////

static void b1_cb(Fl_Widget *w, void *data) {
  Fl_Group *g2 = (Fl_Group *)data;

  if (g2->visible()) {
     g2->hide();
     g3->size(g3->w(),g3->h()+g2->h());
     g2->window()->redraw();
  }
}

static void b2_cb(Fl_Widget *w, void *data) {
  Fl_Group *g2 = (Fl_Group *)data;

  if (!g2->visible()) {
     g3->size(g3->w(),g3->h()-g2->h());
     g2->show();
     g2->window()->redraw();
  }
}



int main(int argc, char **argv) {
  Fl_Button *b1, *b2, *b3;

  Fl_Window *window = new Fl_Window(400, 400, "Fl_Pack test");
  window->begin();
   p1 = new Fl_Pack(0,0,400,400);
   p1->type(Fl_Pack::VERTICAL);
   p1->begin();
    // a Pack with a resizable widget inside
    g1 = new Fl_Group(0,0,0,30, "Group 1");
    g1->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
    g1->box(FL_UP_BOX);
    g1->color(FL_CYAN);
    g1->end();

    g2 = new Fl_Group(0,0,0,30, "Group 2");
    g2->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
    g2->box(FL_UP_BOX);
    g2->color(FL_RED);
    g2->end();

    g3 = new Fl_Group(0,0,0,280, "Group 3     R e s i z a b l e");
    g3->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
    g3->box(FL_UP_BOX);
    g3->color(FL_GREEN);
    g3->end();
    b1 = new Fl_Button(0,340,50,30);
    b1->label("Hide G2");
    b1->callback(b1_cb, g2);
    b2 = new Fl_Button(0,370,50,30);
    b2->label("Show G2");
    b2->callback(b2_cb, g2);
   p1->end();
   p1->resizable(g3);
  window->end();

  window->resizable(window);
  window->show();
  return Fl::run();

  return 0;
}

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

Reply via email to