On 28.10.2011 01:05, Albrecht Schlosser wrote:

Yes - well, it's complicated. I played around with your test
program for a while, and it's confusing.

First point: It's not only the second pack that shows these
strange effects, but it depends on where you click first. If
you click first on the (round) button, then the buttons in
the 2nd pack seem to be dead, and there are no tooltips, as
you described. However, if you resize the window only for a
small bit, then all buttons and tooltips are operative again.
If you *click* on one of the buttons in the second pack, then
the upper (round) button is inactive.

This is clearly a symptom of some shifting/positioning of the
widgets while resizing, and the reason is that Fl_Pack is really
a problematic widget. It has the feature that it resizes itself
to surround all widgets - and to make it worse, this is done in
the draw() method (not in resize() or something else). An additional
feature is that the contained widgets are allowed to resize themselves
when (while) *they* are drawn - and this would be the case for nested
Fl_Pack's.

To get an impression of what happens internally, I attach a slightly
modified test program with these changes:

- the button "Weight Log Regression" has a tooltip and prints some
  widget positions when clicked
- the light button "LOCK" prints the same positions
- you can test both versions (with and w/o resizing) by running the
  program with an additional argument "1" to enable resizing
- in print_cb() there are two "#if 0/1" conditional parts that do
  something "magic"
   (a) init_sizes() resets the saved child coordinates for resizing.
   (b) window->redraw() redraws the window (sic!), but this also
       recalculates positions in the Fl_Pack's.

Surprisingly, this works best, if only (b) is active, although I
first added only (a) - with the effect of "jumping" widgets. Try
yourself...

Note that only activating (b) makes all buttons and tooltips
always responsive! That's not the solution though, just an
intermediate test result. Have fun!

Albrecht
/* main.cc */

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Pack.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Light_Button.H>
#include <FL/Fl_Value_Output.H>

Fl_Double_Window *window = 0;
Fl_Pack *settings = 0;
Fl_Pack *second = 0;
Fl_Pack *hpack = 0;

int resize_yes = 0;

void print_cb(Fl_Widget *, void *) {
  static int num = 0;
  printf("[%d]\nresize   = %d\n",++num,resize_yes);
  printf ("%-8.8s = 
(%4d,%4d,%4d,%4d)\n","window",window->x(),window->y(),window->w(),window->h());
  printf ("%-8.8s = 
(%4d,%4d,%4d,%4d)\n","settings",settings->x(),settings->y(),settings->w(),settings->h());
  printf ("%-8.8s = 
(%4d,%4d,%4d,%4d)\n","second",second->x(),second->y(),second->w(),second->h());
  printf ("%-8.8s = 
(%4d,%4d,%4d,%4d)\n","hpack",hpack->x(),hpack->y(),hpack->w(),hpack->h());
  fflush(stdout);
#if 0
  window->init_sizes();
  settings->init_sizes();
  second->init_sizes();
  hpack->init_sizes();
#endif
#if 1
  window->redraw();
#endif
}

int main(int argc, char **argv)
{
  if (argc > 1) {
    resize_yes = atoi(argv[1]);
    argc = 1; // HACK !
  }
int w = 1012;
int h = 625;
int leftspacer = 29*w/128;
int x = 0, y = 0;

window = new Fl_Double_Window(w,h);

settings = new Fl_Pack(x, y, w, h);
settings->spacing(h/23);
 {
 new Fl_Box(x,y,w,h/640);
 }
 {
 Fl_Pack *o = new Fl_Pack(x,y,w,h/22);
 second = o;
 o->type(Fl_Pack::HORIZONTAL);
 if (resize_yes) o->resizable(o);
 new Fl_Box(x,y,96*w/128,h/22);
  {
  Fl_Button *o = new Fl_Button(x, y, 9*w/40, h/22, "Weight Log Regression");
  o->box(FL_ROUND_UP_BOX);
  o->tooltip("click to print sizes...");
  o->callback(print_cb);
  }
 o->end();
 }

 {
 hpack = new Fl_Pack(x, y, w, h/22);
 hpack->type(Fl_Pack::HORIZONTAL);
 hpack->spacing(w/50);
 if (resize_yes) hpack->resizable(hpack);
  {
  Fl_Box *o = new Fl_Box(x, y, leftspacer, h/22);
  o->color(FL_YELLOW);
  o->box(FL_FLAT_BOX);
  }
  {
  Fl_Box *o = new Fl_Box(x, y, w/6, h/22, "Calories");
  o->align(FL_ALIGN_INSIDE|FL_ALIGN_LEFT);
  }
  {
  new Fl_Value_Output(x, y, w/10, h/22);
  }
  {
  new Fl_Box(x,y, w/75, h/22);
  }
  {
  Fl_Light_Button *clock = new Fl_Light_Button(x, y, w/15, h/22, "LOCK");
  clock->tooltip("When locked, value can't be reset from the analysis screen");
  clock->callback(print_cb);
  }
  {
  new Fl_Box(x,y, w/150, h/22);
  }
  {
  Fl_Light_Button *alock = new Fl_Light_Button(x, y, 2*w/19, h/22, "AUTO-SET");
  alock->tooltip("Blah, Blah, Blah.");
  alock->callback(print_cb);
  }
 hpack->end();
 }

settings->end();
if (resize_yes == 1) settings->resizable(settings);
else if (resize_yes == 2) settings->resizable(hpack);

print_cb(0,0);

window->end();
window->resizable(window);
window->show(argc, argv);
return Fl::run();
}
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to