|
DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: https://www.fltk.org/str.php?L2639
Version: 1.4-feature
Attached file "str2639_rsz_gr.cxx"...
Link: https://www.fltk.org/str.php?L2639
Version: 1.4-feature #include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
Fl_Group *p1;
Fl_Group *g1, *g2, *g3;
////////////////////////////////////////////////////////////////
static void b1_cb(Fl_Widget *w, void *data) {
Fl_Group *g2 = (Fl_Group *)data;
if (g2->visible()) {
// hide g2 first
g2->hide();
// resize g3 to occupy the space of g2
g3->resize(g3->x(), g3->y() - g2->h(), g3->w(), g3->h() + g2->h());
// optionally resize the hidden widget g2 (doesn't matter)
// g2->resize(g2->x(), g2->y(), g2->w(), 0);
// init_sizes() is required after rearranging children
g2->parent()->init_sizes();
g2->parent()->redraw();
}
}
static void b2_cb(Fl_Widget *w, void *data) {
Fl_Group *g2 = (Fl_Group *)data;
if (!g2->visible()) {
// resize g2 first with a *fixed* height (this can't be avoided)
g2->resize(g2->x(), g2->y(), g2->w(), 30);
// resize g3 to free the space used by g2
g3->resize(g3->x(), g3->y() + g2->h(), g3->w(), g3->h() - g2->h());
g2->show();
// init_sizes() is required after rearranging children
g2->parent()->init_sizes();
g2->window()->redraw();
}
}
int main(int argc, char **argv) {
int ww = 400, wh = 400, ypos = 0;
Fl_Button *b1, *b2;
Fl_Window *window = new Fl_Window(ww, wh, "Fl_Group test");
window->begin();
p1 = new Fl_Group(0, 0, ww, wh);
p1->begin();
// a Pack with a resizable widget inside
g1 = new Fl_Group(0, ypos, ww, 30, "Group 1");
g1->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE);
g1->box(FL_UP_BOX);
g1->color(FL_CYAN);
g1->end();
ypos += g1->h();
g2 = new Fl_Group(0, ypos, ww, 30, "Group 2");
g2->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE);
g2->box(FL_UP_BOX);
g2->color(FL_RED);
g2->end();
ypos += g2->h();
g3 = new Fl_Group(0, ypos, ww, 280, "Group 3 R e s i z a b l e");
g3->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE);
g3->box(FL_UP_BOX);
g3->color(FL_GREEN);
g3->end();
ypos += g3->h();
b1 = new Fl_Button(0, ypos, ww, 30);
b1->label("Hide G2");
b1->callback(b1_cb, g2);
ypos += b1->h();
b2 = new Fl_Button(0, ypos, ww, 30);
b2->label("Show G2");
b2->callback(b2_cb, g2);
p1->end();
p1->resizable(g3);
window->end();
window->resizable(p1);
window->show();
return Fl::run();
}
[ Direct Link to Message ] | |