On 04/03/12 09:52, Robert Arkiletian wrote:
> Question from a student I could not answer:
> 
> Want to have 3 horiz groups in a window.
> 
> -top group resizes both horiz and vert
> -middle group resizes only horiz
> -bottom group resizes both horiz and vert
> 
> So the top and bottom will always be the same size.
> Middle group height remains constant.
> 
> Possible?

        There might be a way to do it with a combo of group resizables, but
        I'd take the route of doing custom resize() calculations myself..
        see the MyThreeGroups::resize() method below:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
//
// Demonstrate 3 groups with custom sizing - erco 04/03/12
//
//     3 horiz groups in a window.
//          -top group resizes both horiz and vert
//          -middle group resizes only horiz
//          -bottom group resizes both horiz and vert
//     So the top and bottom will always be the same size.
//     Middle group height remains constant.
//
void MakeFourButtons(int X,int Y,int W,int H) {
  new Fl_Button(X+20,      Y+20,     100,25,"A");
  new Fl_Button(X+W-20-100,Y+20,     100,25,"B");
  new Fl_Button(X+20,      Y+H-20-25,100,25,"C");
  new Fl_Button(X+W-20-100,Y+H-20-25,100,25,"D");
}
class MyThreeGroups : public Fl_Group {
    Fl_Group *top;
    Fl_Group *mid;
    Fl_Group *bot;
public:
    MyThreeGroups(int X,int Y,int W,int H) : Fl_Group(X,Y,W,H) {
        Fl_Align center = FL_ALIGN_CENTER|FL_ALIGN_INSIDE;
        top = new Fl_Group(0,  0,300,150,"Top"); top->align(center); 
top->box(FL_FLAT_BOX); top->color(45); top->begin();
          MakeFourButtons(top->x(), top->y(), top->w(), top->h());
        top->end();
        mid = new Fl_Group(0,150,300,150,"Mid"); mid->align(center); 
mid->box(FL_FLAT_BOX); mid->color(47); mid->begin();
          MakeFourButtons(mid->x(), mid->y(), mid->w(), mid->h());
        mid->end();
        bot = new Fl_Group(0,300,300,150,"Bot"); bot->align(center); 
bot->box(FL_FLAT_BOX); bot->color(49); bot->begin();
          MakeFourButtons(bot->x(), bot->y(), bot->w(), bot->h());
        bot->end();
    }
    // CUSTOM RESIZE CODE FOR TOP/MID/BOT SIZING
    void resize(int X,int Y,int W,int H) {
        // Calculate height of top+bottom groups
        int tbh = (H-mid->h())/2;
        // Calculate y positions for top/mid/bot
        int top_y = Y;
        int mid_y = Y+tbh;
        int bot_y = mid_y+mid->h();
        // Apply new sizes
        top->resize(X,top_y,W,tbh);
        mid->resize(X,mid_y,W,mid->h());
        bot->resize(X,bot_y,W,tbh);
        // Children were repositioned
        init_sizes();
    }
};
int main() {
    Fl_Window win(300,450);
    win.begin();
      MyThreeGroups grp(0,0,300,450);
    win.end();
    win.resizable(grp);
    win.show();
    return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to