> setting the font before calling fl_measure() didn't have the desired
> result. But I found a workaround: before adding the topmost Fl_Output
I
> add a dummy Fl_Output with width = 0 and height = 0.
> And now the topmost widget is measured correctly. So my application
> works properly - but it would be interesting to know why...


I've no idea what you d0 in your actual code, but the example you posted
was incomplete and does not even compile.

Once I fixed it so that it will actually compile, and incorporated the
changes we advised, I had this (see below) and it works perfectly, so I
do not know what the problem you have in your real code can be:

-------------------------------

/*
// testalucida's measure expt.
// fltk-config --compile measure-test.cxx
*/
#include <FL/Fl.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Output.H>
#include <FL/fl_draw.H>

#include <string>
#include <vector>

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_Font curr_font = this->textfont();
        int sz = this->textsize();
        fl_font(curr_font, sz);
        wi = he = 0;
        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( std::vector<std::string> &labels,
std::vector<std::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();

    std::vector<std::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();
}

/* end of file */





SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

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

Reply via email to