Search code examples
c++user-interfacefltk

FLTK Fl_Scrollbar Issue


I have little problem with scrollbar.

The problem is there is no separator anymore if i move the scrollbar back to the top again.

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Box.H>
#define BW 200 //box width
#define BH 50 //box height
#define SEP 10 //separator

int main(){
  Fl_Window win(500, 300);
  Fl_Scroll *scr=new Fl_Scroll(10,10,win.w()-20,win.h()-20);
  scr->color(FL_GREEN);
  int col=scr->w()/BW;
  int c=0,line=SEP;
  for(int i=1;i<=20;i++){
     Fl_Box *b = new Fl_Box(scr->x()+SEP+(c*(BW+SEP)),scr->y()+line,BW,BH);
     b->box(FL_FLAT_BOX);
     b->color(FL_RED);
     c += 1;
     if(c == col){
        c = 0;
        line += (BH + SEP);
     }
  }
  new Fl_Box(SEP,scr->y()+line-SEP,SEP,SEP);
  win.show();
  return Fl::run(); 
}

This is the picture

Thanks.


Solution

  • Can't really tell what the reason is for that behaviour but

    1. If the last Fl_Box is removed, the bottom separator disappears.
    2. If a box is added before the loop, it doesn't lose the top line

      new Fl_Box(SEP,0,SEP,SEP);