Code: Select all
.getTextBounds(string, x, y, &x1, &y1, &w, &h);
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
...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().
andsetCursor(x, y), which will place the top left corner of the text wherever you please
It seems that, in general, GFX defines text and rects relative to the top left corner of the region that contains them.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)
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
What am I missing here?