0

I'm using FLTK for a project (the version distributed with Debian/sid 1.3.2-6+b1) and I'm having some trouble initializing Fl_Scroll's content scroll values.

I create a Fl_Double_Window and on the right side a vertical panel using Fl_Scroll, it is positioned at left x 600 and top y 24.

Then I set Fl_Scroll's type to Fl_Scroll::VERTICAL and place a Fl_Button inside, everything works fine.

The problem? Fl_Scroll initialize already scrolled with xposition() = 600 and yposition() = 24 (X and Y of the Fl_Scroll's constructor?? Is supposed to work so?), instead I want it to initialize with content scrolled at left and top 0, 0, so I tried scroll_to() in different places, before and after window's show(), on FL_SHOW of the subclassed Fl_Scroll (I didn't really need to subclass Fl_Scroll, just trying to get scroll_to() working), also on overridden draw() after the parent draw(), even creating Fl_Scroll at 0, 0 then position() at 600, 24, but nothing.

The only way I got scroll_to() working is if I call it from an async event after the application initialize (FL_KEYUP).

Here's the overridden Fl_Double_Window window constructor:

group = new Fl_Group(0, 0, WIN_W, WIN_H);
{
 menu = new Fl_Menu_Bar(0, 0, WIN_W, MENU_H);
 menu->add("File/Quit",   FL_CTRL+'q', cbMenuQuit_i);

 glview = new CGLView(0, MENU_H, WIN_W-PROPS_W+1, WIN_H-MENU_H);
 group->resizable(glview);

 scroll = new CScroll(WIN_W-PROPS_W, MENU_H, PROPS_W-1, WIN_H-MENU_H);
 scroll->type(Fl_Scroll::VERTICAL);
 {
  Fl_Pack *pack = new Fl_Pack(0, 0, PROPS_W-1, WIN_H-1);
  {
   btnAddLayer = new Fl_Button(0, 0, PROPS_W, 32, "@#+ Add Layer");
   btnAddLayer->callback(btnAddLayerCb_i, (void *)this);
  }
  pack->end();
 }
 scroll->end();
}
group->end();

end();
size_range(WIN_MIN_W, WIN_MIN_H); /* Make the window resizable */
show();
Alex
  • 3,264
  • 1
  • 25
  • 40

1 Answers1

0

Never mind, got it, two altenative:

  • create Fl_Scroll at 0, 0 then position() it after scroll->end()
  • create Fl_Scroll at the wanted position then after scroll->end() use negative values scroll_to(-X, -Y)

In both cases is important that the widgets contained are already added (scroll_to() alter cotained widgets coords)

Isn't clear to me why X and Y of Fl_Scroll's constructor are used.

Alex
  • 3,264
  • 1
  • 25
  • 40
  • Have a look at test/scroll.cxx for an example of how to use Fl_Scroll with Fl_DoubleWindow. – cup Jan 20 '15 at 13:00
  • Thank you @cup, I didn't thought about examples/test within fltk sources, they're not included in Debian fltk packages, downloaded. Still, all the examples I've seen online just offset at 0,0 or don't care about the initial scroll. I suspect is a bug, don't see how setting the window relative x, y for the scroll could be a feature, try `Fl_Scroll scroll(50,50,5*75-50,300-50);` with `test/scroll.cxx` – Alex Jan 20 '15 at 14:36
  • x and y in the Fl_Scroll constructor, like all other FLTK widgets, are for positioning the widget. They do not set the position.of the cursor. Position will also set the position of the widget. – cup Jan 20 '15 at 18:40
  • scroll->end() just indicates that you have finished adding widgets to the scroll group. As you have discovered, scroll_to is the one that positions the cursor. – cup Jan 20 '15 at 21:05
  • Sorry @cup maybe I been not clear enough, my bad, one last try, `Fl_Scroll` initialize the scrollbars *already scrolled* with x, y given in `Fl_Scroll`'s `ctor()`, which doesn't make any sense to me. I'm well aware about what you say in your comments about `x, y` and `end()`, but thanks – Alex Jan 21 '15 at 04:37