FLTK logo

Re: [fltk.general] Understanding Fl_Pack.

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Understanding Fl_Pack. Greg Ercolano Oct 02, 2022  
 
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?

    If for some reason you really need to use Fl_Pack, I only made a few
    small changes here to keep its use, the important changes highlighted in green.
    Had to make some widgets global (shown in magenta).



#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;
      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 );

  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/d44b1955-2534-76f5-33ce-75715f3c774e%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.