GFX getTextBounds()

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
extan
 
Posts: 10
Joined: Sun Feb 11, 2018 8:00 pm

GFX getTextBounds()

Post by extan »

I'm pretty sure I'm gonna feel dumb after hearing the answer, but for now I'm baffled by what I get back after calling:

Code: Select all

.getTextBounds(string, x, y, &x1, &y1, &w, &h);
like:

Code: Select all

const char HelloWorld[] = "Hello World!";
display.setFont(&FreeMonoBold9pt7b);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
Serial.print("tbx: "); Serial.print(tbx); Serial.print(" tby: "); Serial.println(tby);
Serial.print("tbw: "); Serial.print(tbw); Serial.print(" tbh: "); Serial.println(tbh);
>>>

Code: Select all

tbx: 1 tby: -10
tbw: 127 tbh: 11
From the doc:
getTextBounds expects a string, a starting cursor X&Y position (the current cursor position will not be altered), and addresses of two signed and two unsigned 16-bit integers. These last four values will then contain the upper-left corner and the width & height of the area covered by this text — these can then be passed directly as arguments to fillRect().
...
setCursor(x, y), which will place the top left corner of the text wherever you please
and
rectangles and squares can be drawn and filled using the following procedures. Each accepts an X, Y pair for the top-left corner of the rectangle, a width and height (in pixels)
It seems that, in general, GFX defines text and rects relative to the top left corner of the region that contains them.
So I would expect getTextBounds(), when called with something like (HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh) to return something like:

Code: Select all

tbx: 1 tby: 1
tbw: 127 tbh: 11
tbx and tby containing (1,1) (or perhaps 0,0), representing the top left corner of the containing rect. Yet, I see (1,-10), which seems more like relative to the bottom left corner of the rect.

What am I missing here?
Attachments
lcds___displays_rect.png
lcds___displays_rect.png (5.73 KiB) Viewed 259 times

User avatar
extan
 
Posts: 10
Joined: Sun Feb 11, 2018 8:00 pm

Re: GFX getTextBounds()

Post by extan »

I'd really like to understand this.

It seems maybe this topic is mostly about hardware problems with adafruit products. Might you suggest a better place to post this question? #adafruit_support_bill #adafruit

Thanks

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”