On 01.02.2012 12:54, testalucida wrote:
> 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?
Maybe...
> -----------------------------------------------
>
> 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;
change this to
int wi=0, he=0;
You must set at least wi=0, otherwise its (undefined) value will
be used as the maximum width you allow (for wrapping purposes).
See the docs.
> fl_measure( this->value(), wi, he, 0 );
You must set a font before you can measure anything. This may
have been done already, but maybe not. It's a good thing to set
one here to be sure...
> resize( x(), y(), wi + 6, h() );
It is not a good idea to resize the widget in its draw() method.
Although this *may* work, it is like asking for problems.
I suggest to change the first two issues first to see if that helps.
I didn't look closely at the rest of the code, and I didn't test it.
Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk