MacArthur, Ian (SELEX) (UK) schrieb:
> Although really this should be (and under fltk2 has to be...)
>
> Fl_Window* win = new Fl_Window(...)
> win->begin();
> new Fl_Box( ... , "Hello");
> win->end();
>
> I like it this way... But I agree that the "hidden-begin" is probably a
> bad thing and confusing for the unwary!
logically begin() and end() define a new context (aka scope)
although c++ does not support smthng like this it could be done with a
simple macro (okok i know macros are considered goto's)
#define with(group) int
group##once=1;for((group)->begin();group##once--;(group)->end())
which would allow smthng like this (also showing the scope and hirachy
of added widgets):
Window *window = app = new Window(WIN_CX, WIN_CY, "Test");
with(window)
{
MenuBar *menu = new MenuBar(0, 0, window->w(), MHEIGHT, "Menu");
menu->add("&File/&New", 0, 0, 0,INACTIVE);
menu->add("&File/&Open...", 0, 0);
//...
TiledGroup *splitter = new TiledGroup(0, MHEIGHT, window->w()
, window->h()-MHEIGHT-THEIGHT);
splitter->color(fltk::RED);
splitter->box(fltk::FLAT_BOX);
//...
with(splitter)
{
DirPane *g1=new DirPane(0 , 0, splitter->w()/2
, splitter->h());
g1->color(fltk::RED);
g1->box(fltk::DOWN_BOX);
//...
DirPane *g2=new DirPane(splitter->w()/2, 0
, splitter->w()-splitter->w()/2
, splitter->h());
g2->color(fltk::BLUE);
g2->box(fltk::DOWN_BOX);
//...
}
Group *g3 = new Group(0, window->h()-THEIGHT
, window->w(), THEIGHT);
with(g3)
{
char *txt="status bar status bar status bar status bar";
StatusBarGroup *status = new StatusBarGroup(THEIGHT);
status->set(txt,StatusBarGroup::SBAR_LEFT);
status->box(FLAT_BOX);
//...
}
window->resizable(splitter);
}
just my 2ct, begin/end is a little like pascal and there is no need to
ident the inner block. thats the advantage of the with macro (besides
some disadvantages)
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk