Hello!
First I want to confess sin of copypasta. Last night I copied from
scroll.cxx example and got that bad code. I was thinking if this can
be even done with resize()
Ian's code didn't care about scrollbars and they were position()ed all
the time and still worked.. Strange.
It still doesn't come to resizing child. Maybe Fl_Scroll::resize
should be called so that children would be resized (inRow wold be
zero).
Next I'll try put that class to my program and see how it behaves there.
This is my current solution. I got rid of the vector and got some nice
spacing...
Best regards,
Hannu Vuolasaho
class SummaryScroll: public Fl_Scroll {
public:
SummaryScroll(int X, int Y, int W, int H, const char * L = 0):
Fl_Scroll(X,Y,W,H,L)
{
type(Fl_Scroll::VERTICAL);
}
void resize(int X, int Y, int W, int H){
int childCount = children(), i = 0, inRow;
int d = _spacing, dh, dw;
Fl_Widget::resize(X,Y,W,H);
if(childCount>0){
dw = child(0)->w();
dh = child(0)->h();
inRow = (W - Fl::scrollbar_size() - d) / (dw + d);
d += (W - Fl::scrollbar_size() - 2 * d) / inRow - dw - d;
if(inRow){
for(i = 0; i < childCount; ++i){
if(&hscrollbar == child(i))continue;
if(&scrollbar == child(i))continue;
child(i)->position(1 + d + X + (i % inRow) * (dw + d),
1 + _spacing + Y + (i / inRow) * (dh + _spacing));
}
} else {
// Child is too large for window.
// and actually never run...
for(i = 0; i < childCount; ++i){
child(i)->resize(1 + X + (i % inRow) * dw,
1 + Y + (i / inRow) * dh,
W - Fl::scrollbar_size(),
dh);
}
}
Fl_Scroll::init_sizes();
}
}
private:
const static int _spacing = 3;
};
int main(int argc, char** argv) {
Fl_Double_Window window(5*75,400);
window.box(FL_FLAT_BOX);
SummaryScroll scroll(0,0,5*75,300);
int n = 0;
for (int y=0; y<16; y++)
for (int x=0; x<5; x++) {
char buf[20]; sprintf(buf,"%d",n++);
Fl_Box* b = new Fl_Box(x*75,y*25+(y>=8?5*75:0),75,25);
b->copy_label(buf);
b->color(n);
b->labelcolor(FL_WHITE);
b->box(FL_FRAME_BOX);
}
scroll.end();
window.resizable(scroll);
window.end();
window.show(argc,argv);
return Fl::run();
}
/* end of file */
> --
> You received this message because you are subscribed to the Google Groups
> "fltk.general" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
fltkgeneral...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.