On 02.12.2011 11:10, MacArthur, Ian (SELEX GALILEO, UK) wrote:
>
>>> Huh? I don't understand the question.
>>> You get the size of a button just by calling its w() and
>> h() methods.
>>> What property of the widget are you trying to measure other than its
>>> width and height?
>>>
>>
>> The w() and h() methods return the size that the user
>> requested when the widget was created or resized.  What I
>> want is the "shrink-wrap" size.
>> For labels and buttons it is the size of the label and/or
>> image and the surrounding box.
>>
>> For example:
>>
>> void fl_Widget_shrinkwrap_size(Widget *o, int* sizes) {
>>    int w,h;
>>    o->measure(w,h);
>>    if (w>  5&&
>> o->align()&(fltk3::ALIGN_LEFT|fltk3::ALIGN_RIGHT)) {w += 6;}
>>
>>    sizes[0]=w + fltk3::box_dw(o->box());
>>    sizes[1]=h + fltk3::box_dh(o->box());
>> }
>
> Nope, sorry, you've lost me. I'm too thick, but I can't grok what it is
> you are doing here...

I believe he wants something like the layout() method of FLTK 2, but
I know layout() only "from hearsay". IIRC this method is designed to
return the "wanted" size of a widget.

To the OP: Unfortunately it's not as easy as you describe in your pseudo
code. Widgets can have outside labels and images, and if you resize a
widget, many things can happen (the widget can change its font size,
for instance). And, as you showed already, the alignment flags matter.
Hence, only the widget itself can "know" its "shrink-wrap" (minimal?)
size, or even better, its "optimal" size.

Even measuring (multi-line, auto-wrap) text can be ambiguous: the result
depends on the given w (width) value that is to be used as a maximum
width for wrapping, i.e. the "shrink-wrap" size is a (non-linear)
function of the given maximal width.

Hence, only a widget's implementation can decide, how this would be
calculated best, and the combinations of images and (multi-line) labels,
together with alignment flags, make it at least very difficult to
calculate such values. However, FLTK 3 will probably have FLTK 2's
layout() method eventually...

Albrecht
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to