FLTK logo

[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 ]

Understanding Fl_Pack. Gonzalo Garramuno Oct 02, 2022  
 
I have used Fl_Pack in the past and I always struggle with its behavior.  

In the sample attached demo program I have an Fl_Pack that contains an Fl_Gl_Window widget and a normal Fl_Group inside an Fl_Pack.  

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 <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>



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);
    void resize( int X,int Y,int W,int H )
        {
            std::cerr << "win resize W=" << W << std::endl;
            Fl_Gl_Window::resize( X, Y, W, H );
        }
};

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;
  if ( d->visible() ) {
      std::cerr << "hide grp= " << d << std::endl;
      d->hide();
  }
  else {
      std::cerr << "show grp= " << d << std::endl;
      d->show();
  }
  Fl_Pack* pack = (Fl_Pack*)d->parent();
  std::cerr << "pack= " << pack << std::endl;
  pack->init_sizes();
  pack->redraw();
}

int main(int argc, char **argv) {

  Fl::use_high_res_GL(1);
  Fl_Window window(300, 370);
  window.begin();

  Fl_Pack pack(10, 75, 280, 280);
  std::cerr << "pack= " << &pack << std::endl;
  pack.type( Fl_Pack::HORIZONTAL );
  pack.color( FL_CYAN );
  //pack.box( FL_FLAT_BOX );
  pack.begin();

  int H = window.h()-90;
  int W = pack.w()/2;

  shape_window sw(10, 75, W, H );
  sw.end();

  Fl_Group     grp( 0, 75, W, H );
  std::cerr << "grp= " << &grp << std::endl;
  grp.color( FL_RED );
  grp.box( FL_FLAT_BOX );
  grp.end();



  pack.resizable(&sw);
  pack.end();



  Fl_Button button(30, 5, W, 30, "Hide");
  button.callback( hide_cb, &grp );

  window.resizable( &pack );

  window.end();
  window.show(argc,argv);


  return Fl::run();
}



Gonzalo Garramuno
ggarra13@gmail.com




--
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/9CCBF21A-9B0F-44CB-8B5F-9BD3B09EF7AC%40gmail.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'.