Added String overload to getTextBounds() #90

This commit is contained in:
Emil Muratov 2017-08-26 23:09:12 +03:00
parent 1e6251e367
commit 05df41d963
2 changed files with 14 additions and 2 deletions

View File

@ -1392,7 +1392,7 @@ void Adafruit_GFX::charBounds(char c, int16_t *x, int16_t *y,
@param h The boundary height, set by function
*/
/**************************************************************************/
void Adafruit_GFX::getTextBounds(char *str, int16_t x, int16_t y,
void Adafruit_GFX::getTextBounds(const char *str, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) {
uint8_t c; // Current character
@ -1415,6 +1415,15 @@ void Adafruit_GFX::getTextBounds(char *str, int16_t x, int16_t y,
}
}
// Overload for the same as above, but for String strings
void Adafruit_GFX::getTextBounds(const String &str, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) {
if (str.length() != 0) {
getTextBounds(const_cast<char*>(str.c_str()), x, y, x1, y1, w, h);
}
}
/**************************************************************************/
/*!
@brief Helper to determine size of a PROGMEM string with current font/size. Pass string and a cursor position, returns UL corner and W,H.

View File

@ -102,11 +102,14 @@ class Adafruit_GFX : public Print {
setTextWrap(boolean w),
cp437(boolean x=true),
setFont(const GFXfont *f = NULL),
getTextBounds(char *string, int16_t x, int16_t y,
getTextBounds(const char *string, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
getTextBounds(const String &str, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
#if ARDUINO >= 100
virtual size_t write(uint8_t);
#else