Thanks! It works now! It was simply the case of setting the resizable to null.

I've one last problem though. This scrollbar, as you can see, it is a Vertical 
one. What I wanted to do is that if the Fl_Scroll is resized horizontally, this 
also resizes the Fl_Group inside.

I've made a custom Fl_Scrollbar which reimplements the resize method like this:

void CustomScrollbar::resize(int x, int y, int w, int z ) {
        Fl_Scroll::resize(x,y,w,z);

        if ( child(0) )
                child(0)->resize(x+s, y+2*s, w-4*s, child(0)->h());
}

With this it still works fine, it resizes the Fl_Group and it displays 
everything correctly. However it does not resize the fields inside the Fl_Group.

But I'm not sure how to say to the Fl_Group to resize correctly. I've tried to 
add a Fl_Box inside it and setting resizable to it, but as soon as resizable is 
set the problem reappears.

Any idea on how to get this functionality? Thanks again for all the help!



> 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