DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: http://www.fltk.org/str.php?L2692
Version: 1.4-feature
Attached file "main.cpp"...
Link: http://www.fltk.org/str.php?L2692
Version: 1.4-feature
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <vector>
#include <FL/fl_ask.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Pack.H>
#include <FL/Fl_Scroll.H>
const unsigned int bw = 130;
const unsigned int bh = 30;
const unsigned int sp = 5;
const unsigned int mh = 200;
class DumbGroup : public Fl_Group
{
public:
DumbGroup(int x, int y, int w, int h, const char* label=0);
};
class TestGroup : public Fl_Group
{
public:
Fl_Button* add;
Fl_Button* remove;
Fl_Scroll* scrollbox;
Fl_Box* spacer;
Fl_Pack* pack;
void add_phase();
void remove_phase();
TestGroup(int x, int y, int w, int h );
};
DumbGroup::DumbGroup(int x, int y, int w, int h, const char* label) :
Fl_Group(x, y, w, h, label)
{
color(FL_YELLOW);
box(FL_ENGRAVED_FRAME);
align(FL_ALIGN_TOP | FL_ALIGN_INSIDE );
labelsize(24);
}
std::vector<DumbGroup*> phase;
void add_phaseCB(Fl_Widget* w, void* g)
{
((TestGroup*) g)->add_phase();
}
void remove_phaseCB(Fl_Widget* w, void* g)
{
((TestGroup*) g)->remove_phase();
}
TestGroup::TestGroup(int x, int y, int w, int h) : Fl_Group(x, y, w, h)
{
begin();
add = new Fl_Button(x+sp, y+sp, bw, bh, "Add
Widget");
remove = new Fl_Button(x+sp+bw+sp, y+sp, bw, bh,
"Remove Widget");
spacer = new Fl_Box(x+2*bw+3*sp, y+bh+mh+3*sp, w-2*bw-3*sp, sp);
scrollbox = new Fl_Scroll(x+sp, y+sp+bh+sp, w-2*sp, mh+20);
scrollbox->begin();
pack = new Fl_Pack( x+sp, y+sp+bh+sp, sp, mh);
scrollbox->end();
end();
add-> callback( add_phaseCB, this);
remove->callback(remove_phaseCB, this);
spacer->box(FL_NO_BOX);
resizable(spacer);
scrollbox->box(FL_ENGRAVED_FRAME);
scrollbox->type(Fl_Scroll::HORIZONTAL);
pack->box(FL_DOWN_FRAME);
pack->type(Fl_Pack::HORIZONTAL);
pack->spacing(sp);
}
void TestGroup::remove_phase()
{
if(phase.size() <= 1)
{
fl_alert("There must be at least one phase.");
return;
}
fprintf(stderr, "Remove %s\n", phase.back()->label());
pack->remove(phase.back());
pack->redraw();
scrollbox->redraw();
if(pack->w() <= scrollbox->w())
scrollbox->scroll_to(2, 0);
else
scrollbox->scroll_to( pack->w() -scrollbox->w()-phase.back()->w()-sp, 0);
delete phase.back();
phase.pop_back();
}
void TestGroup::add_phase()
{
char label[15] = "";
phase.push_back( new DumbGroup( 0, 0, mh, mh));
sprintf(label, "Phase %d", phase.size());
phase.back()->copy_label(label);
fprintf(stderr, "Add %s\n", phase.back()->label());
pack->add(phase.back());
pack->redraw();
scrollbox->redraw();
if(pack->w() > scrollbox->w())
scrollbox->scroll_to( pack->w() -scrollbox->w()+phase.back()->w()+sp, 0);
else
scrollbox->scroll_to(2, 0);
pack->show();
fprintf(stderr, "x position: %d\n", scrollbox->xposition());
}
int main(int argc, char* argv[])
{
Fl_Double_Window* win;
win = new Fl_Double_Window( 1000, 600, "Scrolling a Fl_Pack that
changes during runtime");
win->begin();
TestGroup* test = new TestGroup(sp, sp+30, win->w()-2*sp, win->h()-2*sp-30);
win->end();
win->resizable(test);
win->show();
return(Fl::run());
}
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev