Hi all,

I'm trying to create several Fl_Output derived controls on demand and put them 
by columns into a Fl_Double_Window. The width of each Fl_Output shall go with 
its value, e.g. for a value "A" width should be 10 and for a value 
"MyTestValue" it should be 110.
The measurement of values is done in the draw() method.

That works fine except for the top one: its width always is minimum.
Can someone help me?

Thanks in advance
testalucida
-----------------------------------------------

Here goes my code:

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>


class Display : public Fl_Output {
public:
        Display( int x, int y, int w, int h, const char *lbl ) :
        Fl_Output(x,y,w,h,lbl)
        {
                textsize( 11 );
        }

protected:
        void draw() {
                int wi, he;
                fl_measure( this->value(), wi, he, 0 );
                resize( x(), y(), wi + 6, h() );
                Fl_Output::draw();
        }
};

//=====================================================

class TestDisplay : public Fl_Group {
public:
        TestDisplay( int x, int y, int w, int h ) : Fl_Group( x, y, w, h ) {
        }

        void setData( vector<string> &labels, vector<string> &values ) {
                for( int i = 0, imax = labels.size(); i < imax; i++ ) {
                        fprintf( stderr, "label: %s\n", labels.at( i ).c_str() 
);
                        Display *pDy = new Display( 150, y() + 3 + i * 30, 150, 
25, labels.at( i ).c_str() );
                        pDy->value( values.at( i ).c_str() );
                        add( pDy );
                }
        }
};

//====================================================

int main() {
        Fl_Double_Window *pWin = new Fl_Double_Window( 100, 100, 300, 300, 
"TestDisplay" );

        TestDisplay *pDisp = new TestDisplay( 0, 0, 300, 300 );

        pWin->end();

        pWin->show();


        vector<string> labels, values;
        labels.push_back( "Label 1: " );
        labels.push_back( "Label 2: " );
        labels.push_back( "Label 3: " );

        values.push_back( "Val 1: " );
        values.push_back( "TestValue 2: " );
        values.push_back( "Value 3: " );

        pDisp->setData( labels, values );

        return Fl::run();
}

_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to