TinyScreen -- Is it possible to measure strings?

tastewar

  • Full Member
  • ***
    • Posts: 26
    • View Profile
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?


tastewar

  • Full Member
  • ***
    • Posts: 26
    • View Profile
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.


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 392
    • View Profile
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.


tastewar

  • Full Member
  • ***
    • Posts: 26
    • View Profile

Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 392
    • View Profile
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.



 

SMF spam blocked by CleanTalk