|
|
On 10/2/22 15:01, Gonzalo Garramuno wrote:
I have used Fl_Pack in the past and I always
struggle with its behavior.
One last followup:
I noticed this bit in the Fl_Pack docs:
The '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.
..which means if your
gl window were added to the pack last, instead of first,
you'd get the behavior you want with the
stretchy GL window. Then your show()/hide()
stuff works unmodified. See the below code for proof of
concept.
This change in child creation order does, however, put your GL window
to the right of the pack instead of the left, which
may be bad for your UX.
Perhaps Fl_Pack can be modified (an RFE) to allow an option
flag that would
allow this stretch behavior with the pack's resizable() regardless
of what order
it appears in the group's hierarchy.
#include <iostream>
#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;
d->hide();
// simple hide() of red group
} else {
std::cerr << "show red= " << d <<
std::endl;
d->show(); // simple show()
of red group
}
G_pack->init_sizes();
}
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;
Fl_Group red( 0, 75, W, H );
std::cerr << "red= " << &red <<
std::endl;
red.color( FL_RED );
red.box( FL_FLAT_BOX );
red.end();
// SHAPE_WINDOW MOVED /AFTER/ RED GROUP
G_sw = new shape_window(10, 75, W, H );
G_sw->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 );
window.end();
window.show(argc,argv);
return Fl::run();
}
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/0846c657-a9fa-ab1a-e5f7-c13813d63954%40seriss.com.
[ Direct Link to Message ] | |
|
| |