On 12/08/2011 09:47 AM, Matthias Melcher wrote:
>
> There is something similar in FLTK 2. It has a virtual function named 
> "layout()" that adjusts widgets sizes and available space. I am planning on 
> using the layout mechanism in 3 - unless of course there is abetter way?!

This is not working in fltk2.

Having tried some more experiments I don't think that idea will work. 
The intention was that layout() would alter the widget's size to any 
requirements and then the caller (the layout() of the parent) would 
adjust to this. But it would cause repeated calls to layout() and be 
wasteful.

New version would be to add a virtual measure function:

   void Widget::measure(int& width, int& height)

This function should modify the passed width and height to take into 
account any limitations of the widget. For most widgets it will enlarge 
them to accommodate a minimum size due to the label and borders (though 
it can do other things, like round to an increment larger than 1 pixel). 
The values are preset to the size the caller wants (widget probably 
should not make it smaller unless it has a really good reason, and this 
is used to figure out wrapping so the height can increase as the width 
gets smaller). The caller may disobey these values and force the size to 
something it wants but the widget is allowed to mis-draw in this case.

There is no real need for a virtual layout() function because it is 
always called immediately before draw(). So it may be better for draw() 
to just check if the LAYOUT_DAMAGE flag is on to indicate a new size, 
this will avoid overhead in the many cases where layout() does nothing. 
This is pretty much how fltk1 works now.

One idea that is working from fltk2 is to put a "VERTICAL" flag on 
widgets to indicate what direction they go in. This seems to provide a 
lot of useful information to a parent about the desired layout, with 
minimal overhead.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to