Joined: July 2004
||Posted: July 16 2006,05:08
I've been playing with Lua FLTK for quite a while, and I continue to find it very frustrating that the available documentation is as vague as it can possibly be without being completely useless.
So I'm making this thread to post anything that I might learn from trial-and-error or sources other than printed docs. I hope that if other people have some pearls that cannot be found without experimentation that they will also post.
To start things off, there is a nice little thing about fonts that I just discovered today, by chance more than anything else.
The documentation includes the following about setting fonts:
|Font:set_font(Font f): integer|
Set the font string of a Font.
Anyone understand the syntax used here? No, of course not, because not only is it vague, but it is also inaccurate. I've tried many times over the last several months to do something with this bit of code, and get nothing but errors or segfaults. It was only after i tried to use it "in a way that i would have done it if i had written lua fltk"....like this:
Now it would have been much easier to understand if they had mentioned the fact that "Font f" represents two parameters, separated by a comma, and that ": integer" is not a part of the function but instead is apparently the return value of the function.
Anyway....now I can finally set whatever font i want simply, without the need to load the entire pile of system fonts into the font table, and without wondering whether or not flua is going to choke on one or more of them.
This is also useful for changing the font in the built-in dialog boxes (file browser, for example). Since most visual properties of these dialogs are static, you can't tell it what font to use...it always uses Font.helvetica. However, you can tell flua what Font.helvetica is before the dialog is opened, so it will use your custom font for the dialog.
The "Font:set_fonts()" function can be unpredictable, and so far I have not used it without running into a situation where certain (broken?) fonts will screw up indexing of the fonts table. I haven't found a solution beyond using specific strings to load only certain font sets.
Apparently Lua FLTK does not handle font aliases well, if at all. When using custom fonts it is best to use the full font name (-*-whatever-blah-blah-*-whatever-*), or at least provide a useable font size, to prevent the font from looking crunchy.