On 10/2/22 15:01, Gonzalo Garramuno wrote:
I have used Fl_Pack in the past and I always struggle with its behavior.
..which is why when you hide the red group, the gl group doesn't enlarge,This widget was designed to add the functionality of compressing and aligning widgets.
If type() is Fl_Pack::HORIZONTAL all the children are resized to the height of the Fl_Pack,
and are moved next to each other horizontally. [..] Then the Fl_Pack resizes itself to surround the child widgets.
I would like the Fl_Gl_Window widget to stretch and fill the Fl_Pack whenever the Fl_Group is hidden when the Hide button is clicked. How can I do that?
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Pack.H>
#include <FL/Fl_Group.H>
#include <FL/math.h>
#include <FL/gl.h>
#include <FL/Fl_Gl_Window.H>
Fl_Pack *G_pack = 0; // global pack (since parenting of red grp changes)
class shape_window : public Fl_Gl_Window {
void draw();
public:
int sides;
shape_window(int x,int y,int w,int h,const char *l=0);
};
shape_window *G_sw = 0;
shape_window::shape_window(int x,int y,int w,int h,const
char *l) :
Fl_Gl_Window(x,y,w,h,l) {
sides = 3;
}
void shape_window::draw() {
if (!valid()) {
valid(1);
glLoadIdentity();
glViewport(0,0,pixel_w(),pixel_h());
}
// draw an amazing but slow graphic:
glClear(GL_COLOR_BUFFER_BIT);
glColor3f( 0.5, 0.5, 0.75 );
glBegin(GL_POLYGON);
for (int j=0; j<sides; j++) {
double ang = j*2*M_PI/sides;
glVertex3f((GLfloat)cos(ang), (GLfloat)sin(ang),
0);
}
glEnd();
}
// when you change the data, as in this callback, you
must call redraw():
void hide_cb(Fl_Widget *o, void *p) {
Fl_Group *d = (Fl_Group *)p;
Fl_Window *win = d->top_window();
if ( d->visible() ) {
std::cerr << "hide red= " << d <<
std::endl;
win->add(d); // move
out of pack -> window group
d->hide(); // and
hide() until needed
} else {
std::cerr << "show red= " << d <<
std::endl;
d->show(); // show and..
G_pack->add(d); // move out of window
group and back into G_pack
G_sw->size(G_pack->w()/2, G_sw->h());
// force gl back to 1/2 size
}
}
int main(int argc, char **argv) {
Fl::use_high_res_GL(1);
Fl_Window window(300, 370);
window.begin();
G_pack = new Fl_Pack(10, 75, 280, 280);
std::cerr << "G_pack= " << G_pack <<
std::endl;
G_pack->type( Fl_Pack::HORIZONTAL );
G_pack->color( FL_CYAN );
//G_pack->box( FL_FLAT_BOX );
G_pack->begin();
int H = window.h()-90;
int W = G_pack->w()/2;
G_sw = new shape_window(10, 75, W, H );
G_sw->end();
Fl_Group red( 0, 75, W, H );
std::cerr << "red= " << &red <<
std::endl;
red.color( FL_RED );
red.box( FL_FLAT_BOX );
red.end();
G_pack->resizable(G_sw);
G_pack->end();
Fl_Button button(30, 5, W, 30, "Hide");
button.callback( hide_cb, &red );
window.resizable( G_pack );
On 10/2/22 15:01, Gonzalo Garramuno wrote:
I have used Fl_Pack in the past and I always struggle with its behavior.
The..which means if your gl window were added to the pack last, instead of first,'resizable()'
for Fl_Pack is set to NULL by default. Its behavior is slightly different
than in a normal Fl_Group widget: only if the resizable() widget is the last widget
in the group it is extended to take the full available width or height, respectively,
of the Fl_Pack group.
On 10/2/22 15:01, Gonzalo Garramuno wrote:
I have used Fl_Pack in the past and I always struggle with its behavior.
You might be able to use Albrecht's new Fl_Flex widget (new in 1.4.x) for this,
I'm not sure. He can probably advise.
On 10/3/22 01:22 Greg Ercolano wrote:
You might be able to use Albrecht's new Fl_Flex widget (new in 1.4.x) for this,
I'm not sure. He can probably advise.
Yes, probably. I didn't try Gonzalo's demo program though. But Gonzalo's statement "I would like the Fl_Gl_Window widget to stretch and fill the Fl_Pack whenever the Fl_Group is hidden when the Hide button is clicked" sounds like a good reason to use Fl_Flex.
On 10/3/22 13:37, Albrecht Schlosser wrote:
OK, I had some spare time and tried Gonzalo's demo. I replaced Fl_Pack with Fl_Flex everywhere and changed:
With these minimal changes Gonzalo's program does what I think he wanted to achieve.// pack->init_sizes();pack->layout();// pack->redraw();
Full demo program attached as 'understanding_fl_pack.cxx'.