On 03.04.2012 19:50, Greg Ercolano wrote:
> 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:
Yeah, I tried it with resizables (e.g. adding a box with zero height),
but didn't succeed, and I also used a custom resize() method, which
I'd have done in my own program anyway.
Greg, your example lacks the group's own resize, hence the
buttons can move outside their parent group, and then become
inoperative. You can try it by resizing the window onyl
horizontal (making it wider). This can be easily solved,
like this:
> // 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();
Fl_Widget::resize(X,Y,W,H); // add this line to resize the group
itself.
> }
> };
FWIW, I'll add my demo here as well. The resize() method is
different, but very similar...
Albrecht
// --- snip ---
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Button.H>
class My_Group : public Fl_Group {
public:
My_Group(int X, int Y, int W, int H ) : Fl_Group(X,Y,W,H) {};
void resize(int X, int Y, int W, int H) {
if (children() == 3) {
int y = Y;
int h1 = child(1)->h(); // middle
int h0 = (H-h1)/2; // top and bottom
child(0)->resize(X,y,W,h0);
y += h0;
child(1)->resize(X,y,W,h1);
y += h1;
child(2)->resize(X,y,W,h0);
init_sizes();
}
Fl_Widget::resize(X,Y,W,H); // resize the group
}
};
int main(int argc, char **argv) {
Fl_Group *g0, *g1, *g2, *g3;
Fl_Window *window = new Fl_Window(600, 500, "resize test");
window->begin();
g0 = new My_Group(0,0,600,500);
g1 = new Fl_Group(0,0,600,200);
g1->box(FL_FLAT_BOX);
g1->color(FL_BLUE);
g1->end();
g2 = new Fl_Group(0,200,600,100);
g2->box(FL_FLAT_BOX);
g2->color(FL_YELLOW);
g2->end();
g3 = new Fl_Group(0,300,600,200);
g3->box(FL_FLAT_BOX);
g3->color(FL_GREEN);
g3->end();
g0->end();
window->end();
window->resizable(window);
window->size_range(200,120);
window->show();
return Fl::run();
}
// --- snip ---
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk