Skip to content

Commit 05df41d

Browse files
committed
Added String overload to getTextBounds() #90
1 parent 1e6251e commit 05df41d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Adafruit_GFX.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ void Adafruit_GFX::charBounds(char c, int16_t *x, int16_t *y,
13921392
@param h The boundary height, set by function
13931393
*/
13941394
/**************************************************************************/
1395-
void Adafruit_GFX::getTextBounds(char *str, int16_t x, int16_t y,
1395+
void Adafruit_GFX::getTextBounds(const char *str, int16_t x, int16_t y,
13961396
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) {
13971397
uint8_t c; // Current character
13981398

@@ -1415,6 +1415,15 @@ void Adafruit_GFX::getTextBounds(char *str, int16_t x, int16_t y,
14151415
}
14161416
}
14171417

1418+
// Overload for the same as above, but for String strings
1419+
void Adafruit_GFX::getTextBounds(const String &str, int16_t x, int16_t y,
1420+
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) {
1421+
if (str.length() != 0) {
1422+
getTextBounds(const_cast<char*>(str.c_str()), x, y, x1, y1, w, h);
1423+
}
1424+
}
1425+
1426+
14181427
/**************************************************************************/
14191428
/*!
14201429
@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.

Adafruit_GFX.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ class Adafruit_GFX : public Print {
102102
setTextWrap(boolean w),
103103
cp437(boolean x=true),
104104
setFont(const GFXfont *f = NULL),
105-
getTextBounds(char *string, int16_t x, int16_t y,
105+
getTextBounds(const char *string, int16_t x, int16_t y,
106106
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
107107
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
108+
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
109+
getTextBounds(const String &str, int16_t x, int16_t y,
108110
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
109111

112+
110113
#if ARDUINO >= 100
111114
virtual size_t write(uint8_t);
112115
#else

0 commit comments

Comments
 (0)