On 22 Oct 2011, at 21:41, David wrote: > > But I shouldn't have to know what font would be used by the Fl_Widget that is > going to be created. I don't know what's being used, what if someone changes > it to be FL_DEFAULT_FONT or FL_SYSTEM_FONT, etc.. I just want to ask a the > widget what size this label will be printed as if I create the widget and > pass the label without setting any font or font size. This way I can calc my > widget size prior to creating the widget for certain types of widget (text > mainly, maybe buttons).
We can debate this ad infinitum, but the bottom line is that what you are asking for doesn't fit well in the fltk architecture... The measure functions can be called at any time, and outside the context of any specific widget, so unless you explicitly set the face and size before you call the text measure function, the results are indeterminate... Now, if you only call the measure function within the widgets draw method, you *probably* don't need to set up the face and size, since the draw method will do that when setting up the context for the widget. But measuring an arbitrary string, well, unless you declare what face and size you want, then there's nothing to measure... There's no default face... It's increasingly obvious that you find this uncomfortable - it is presumably at odds with what was considered normal in whatever toolkit you used previously - but nevertheless this is where we are. The right thing to do (in a fltk context, anyway, other toolkits may vary!) is to call fl_font() to set the current face/size you want, measure your strings, and create your widgets - making sure to set the label face and size as you do so, to ensure that there is no chance of them inadvertently acquiring some alternate face/size. This is a handful of "extra" lines called once at initialisation of the widget, so it seems an utterly negligible cost for the explicit control it provides... I guess that's all I've got to say about this. _______________________________________________ fltk-dev mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk-dev
