My problem is that I have to swap the contents of the Scroll multiple times 
with custom Groups ( it depends on the selected Item of a Tree ). The Group is 
one of them, and I use it so that I can insert it and take it out with one line 
of code instead that of three ( for this one, I also have more complex groups ).

This is the minimal code I've managed to make it work for. Note that again, if 
the Fl_Scroll is resized everything shows up normally, but if the whole thing 
is scroll way down it just vanishes. ( Add like 20 buttons or so )

In code I've also reimplemented the resize code of the group so that it does 
not stretch the inputs, but that's pretty trivial ( calls Fl_Group:: resize and 
then resizes its childs manually )

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_Group * A = new Fl_Group(20,40,300,300,"A");
                                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();
}


ASKER.H

#ifndef ASKER_H
#define ASKER_H

#include <FL/Fl_Pack.h>
#include <FL/Fl_Button.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
        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
        asker->parent()->size(asker->parent()->w(), asker->parent()->h() + 
asker->d + asker->s );       // Increases the Height of the parent by the new 
Widget + 1 Spacing
        asker->parent()->redraw();
}

#endif // ASKER_H

> On 05/13/12 18:17, Eugenio Bargiacchi wrote:
> > I've made within my main window a Fl_Scroll.
> >
> > Inside it there is a Fl_Group, which has two Fl_Input and a Fl_Pack.
> >
> > Inside of the Fl_Pack there is a Fl_Button, which, if pressed, adds a 
> > Fl_Input within the Fl_Pack and increases the size of the Fl_Group to house 
> > the increased Fl_Pack.
> >
> > Fl_Window
> >    '-- Fl_Scroll ( Vertical )
> >           '-- Fl_Group
> >                  +-- Fl_Input 1
> >                  +-- Fl_Input 2
> >                  '-- Fl_Pack ( Vertical )
> >                         '-- Fl_Button ( adds Fl_Inputs to Fl_Pack )
> >
> > However, if the height of the Fl_Group exceeds the height of the Fl_Scroll 
> > and I try to scroll down to see the added fields, the Fl_Scrolls fails to 
> > render them.
> >
> > This happens as soon as the Fl_Scroll is scrolled. If I resize the Window 
> > so that its new size is bigger than the Fl_Group, it is rendered correctly, 
> > but as soon as I add more inputs and I try to scroll down, nothing is 
> > rendered.
> >
> > Am I doing something wrong or is this a bug? If the latter, is there a 
> > workaround?
>
>       Might need to see your code as a reduced *compilable* example
>       (like the below).
>
>       Fl_Scroll is a group already, so perhaps there's no need for
>       the extra Fl_Group, and therefore can avoid having to 'grow' it
>       when the pack enlarges.
>
>       So for instance, if I remove the extra group, I end up with:
>
> #include <FL/Fl.H>
> #include <FL/Fl_Window.H>
> #include <FL/Fl_Scroll.H>
> #include <FL/Fl_Input.H>
> #include <FL/Fl_Pack.H>
> #include <FL/Fl_Button.H>
> void Add_CB(Fl_Widget *w, void *data) {
>     Fl_Pack *pak = (Fl_Pack*)data;
>     pak->begin();
>     new Fl_Input(10,0,200,25);
>     pak->end();
>     pak->window()->redraw();
> }
> int main() {
>     Fl_Window *win = new Fl_Window(400,300);
>     Fl_Scroll *scr = new Fl_Scroll(10,10,400-20,300-20);
>     Fl_Input  *in1 = new Fl_Input(140,20,200,25,"Input 1");
>     Fl_Input  *in2 = new Fl_Input(140,55,200,25,"Input 2");
>     Fl_Button *but = new Fl_Button(140,90,100,25,"Add..");
>     Fl_Pack   *pak = new Fl_Pack(10,135,400-40,10,"Pack");
>     pak->end();
>     pak->type(Fl_Pack::VERTICAL);
>     pak->box(FL_DOWN_FRAME);
>     but->callback(Add_CB, (void*)pak);
>     win->end();
>     win->resizable(scr);
>     win->show();
>     return(Fl::run());
> }
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to