Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,19 @@ void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t
## Text operations

``` C++
void drawString(int16_t x, int16_t y, String text);
void drawString(int16_t x, int16_t y, const String &text);

// Draws a String with a maximum width at the given location.
// If the given String is wider than the specified width
// The text will be wrapped to the next line at a space or dash
void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, String text);
void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, const String &text);

// Returns the width of the const char* with the current
// font settings
uint16_t getStringWidth(const char* text, uint16_t length);

// Convencience method for the const char version
uint16_t getStringWidth(String text);
uint16_t getStringWidth(const String &text);

// Specifies relative to which anchor point
// the text is rendered. Available constants:
Expand Down
8 changes: 4 additions & 4 deletions src/OLEDDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ void OLEDDisplay::drawStringInternal(int16_t xMove, int16_t yMove, char* text, u
}


void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, String strUser) {
void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, const String &strUser) {
uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS);

// char* text must be freed!
Expand Down Expand Up @@ -644,7 +644,7 @@ void OLEDDisplay::drawStringf( int16_t x, int16_t y, char* buffer, String format
drawString( x, y, buffer );
}

void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, String strUser) {
void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, const String &strUser) {
uint16_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS);
uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS);

Expand Down Expand Up @@ -707,7 +707,7 @@ uint16_t OLEDDisplay::getStringWidth(const char* text, uint16_t length) {
return max(maxWidth, stringWidth);
}

uint16_t OLEDDisplay::getStringWidth(String strUser) {
uint16_t OLEDDisplay::getStringWidth(const String &strUser) {
char* text = utf8ascii(strUser);
uint16_t length = strlen(text);
uint16_t width = getStringWidth(text, length);
Expand Down Expand Up @@ -1074,7 +1074,7 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt
}

// You need to free the char!
char* OLEDDisplay::utf8ascii(String str) {
char* OLEDDisplay::utf8ascii(const String &str) {
uint16_t k = 0;
uint16_t length = str.length() + 1;

Expand Down
8 changes: 4 additions & 4 deletions src/OLEDDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,22 @@ class OLEDDisplay : public Stream {
/* Text functions */

// Draws a string at the given location
void drawString(int16_t x, int16_t y, String text);
void drawString(int16_t x, int16_t y, const String &text);

// Draws a formatted string (like printf) at the given location
void drawStringf(int16_t x, int16_t y, char* buffer, String format, ... );

// Draws a String with a maximum width at the given location.
// If the given String is wider than the specified width
// The text will be wrapped to the next line at a space or dash
void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, String text);
void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, const String &text);

// Returns the width of the const char* with the current
// font settings
uint16_t getStringWidth(const char* text, uint16_t length);

// Convencience method for the const char version
uint16_t getStringWidth(String text);
uint16_t getStringWidth(const String &text);

// Specifies relative to which anchor point
// the text is rendered. Available constants:
Expand Down Expand Up @@ -378,7 +378,7 @@ class OLEDDisplay : public Stream {
void sendInitCommands();

// converts utf8 characters to extended ascii
char* utf8ascii(String s);
char* utf8ascii(const String &s);

void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const uint8_t *data, uint16_t offset, uint16_t bytesInData) __attribute__((always_inline));

Expand Down