On 14.05.2012 20:41, Albrecht Schlosser wrote:

> (2) rb (resize-box) was added to maintain the other widgets's sizes.

I just checked another idea: instead of adding the resize box, just
disable the group's own resizing by setting the group's resizable()
to NULL.

... well, then you can also remove the init_sizes() call, and the
statement `group->redraw()` seems to be unnecessary as well.

After all, there's not much I changed for a working sample code.
Essentially it's the top-left box for Fl_Scroll spacing, setting
the group's resizable() to NULL, and adding one redraw() call.

Does this (see inline code below) work for you?

Albrecht

// asker.h
#ifndef ASKER_H
#define ASKER_H

#include <FL/Fl_Pack.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <FL/fl_ask.H>

template <class T>
class Asker : public Fl_Pack
{
   public:
     Asker(int a, int b, int c, int d, const char * itemName, int s);
   private:
     Fl_Button * addButton;
     static void add_cb( Fl_Widget * button, void * a );
     int s;
     int d;
};

template <class T>
Asker<T>::Asker(int a, int b, int c, int d2, const char * itemName, int 
s2) : Fl_Pack( a, b, c, d2 ) , s(s2), d(d2)
{
   add(addButton = new Fl_Button( a, b, c, d, itemName));       // Creates the 
gen button
   addButton->callback((Fl_Callback*) add_cb, this );           // Creates the 
gen callback
   end();
   spacing(s);
}

template <class T>
void Asker<T>::add_cb( Fl_Widget * button, void * a ) {
   Asker<T> * asker = ( Asker<T> * ) a;         // Gets the caller
   Fl_Group *group = (Fl_Group *)asker->parent();    // parent = 
Fl_Group (!)
   Fl_Scroll *scroll = (Fl_Scroll *)group->parent(); // group's parent = 
Fl_Scroll (!)
   T * newWidget = new T(0 , 0 , 0 ,asker->d);  // Creates the new 
widget, only height matters because Fl_Pack
   asker->insert(*newWidget, 0);                        // Inserts the new 
Widget on top
   group->size(group->w(), group->h() + asker->d + asker->s );  // 
Increases the Height of the parent by the new Widget + 1 Spacing
   scroll->redraw();    // MUST BE DONE
}

#endif // ASKER_H
// end of asker.h
//----------------------------------------------------------

// asker.cxx
// (MAIN.CPP)
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Input.H>
#include "asker.h"

int main(int argc, char **argv) {
   Fl_Window *window = new Fl_Window(340,400);
     Fl_Scroll *Z = new Fl_Scroll(0,0,340,400);
       Fl_Box * top_box = new Fl_Box(0,0,3,3);          // to keep spacing in 
Fl_Scroll
       // top_box->color(FL_RED); top_box->box(FL_FLAT_BOX); // make it 
visible (comment this out!)
       Fl_Group * A = new Fl_Group(20,40,300,300,"A");
        A->resizable(0); // needed to keep the other widgets in their original 
sizes
        Fl_Input * A1 = new Fl_Input( 30, 50, 280, 40, "A1" );
        Asker<Fl_Input> * B = new Asker<Fl_Input>(30, 100, 280, 40, "TEST", 
10 );   // Each Input will be 40 height, spacing is 10
       A->end();
       A->box(FL_UP_BOX);
     Z->end();
   window->end();
   window->resizable(window);
   window->show(argc, argv);
   return Fl::run();
}
// end of asker.cxx
//----------------------------------------------------------
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to