TinyCircuits Forum

TinyCircuits Products => TinyDuino Processors & TinyShields => Topic started by: tastewar on January 08, 2016, 11:31:01 AM

Title: TinyScreen -- Is it possible to measure strings?
Post by: tastewar on January 08, 2016, 11:31:01 AM
In order to display strings centered, it'd be helpful to know how much space a given string will take up, esp. if they aren't known at build time. I see that there are 12 varieties of liberationSans available: 8, 10, 12, 14, 16, 22 pt in both "normal" and narrow. It looks like, for instance for the 8pt, you have a table "liberationSans_8ptDescriptors" which has these widths and the FONT_INFO struct tells me what the starting character is. So if I could retrieve that info, I could probably do what I need, but there appears to be no "getFont" method, and the font parameters in the class are all private. Oh the other piece of info I need is how much space there is between characters? Is it one pixel?

I guess what I am inclined to do at this point is to define my own function, e.g. setFontX which will call the TinyScreen's setFont method, but which will also remember it in a global so I can later retrieve it for measuring strings.

Any better ideas? Any chance of getting a getFont or getFontDescriptor method?
Title: Re: TinyScreen -- Is it possible to measure strings?
Post by: tastewar on January 08, 2016, 02:51:00 PM
I've forked the repo and have written a TinyScreen::getStringMeasurements method. Once I'm sure it's working, I'll create a pull request, unless you'd rather I didn't bother.
Title: Re: TinyScreen -- Is it possible to measure strings?
Post by: Ben Rose on January 19, 2016, 02:03:06 PM
Hi- just back from holiday. I haven't check your further posts in other threads, but this is something I've played with before- I'll take a look at your implementation and make sure something gets into the next library update, since this is such a useful feature.
Title: Re: TinyScreen -- Is it possible to measure strings?
Post by: tastewar on January 20, 2016, 10:18:55 PM
Hi Ben- I created a pull request. Do with it as you will!
Title: Re: TinyScreen -- Is it possible to measure strings?
Post by: Ben Rose on January 22, 2016, 12:41:48 PM
Thank you. We've merged it, I'll probably 'arduinofy' it very soon in the next update- just split it into two functions so that each can return a single result.
Title: Re: TinyScreen -- Is it possible to measure strings?
Post by: tastewar on January 22, 2016, 10:06:54 PM
Thanks, Ben!