Skip to content

Commit

Permalink
Added text_width/text_xcenter.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcmerlin committed Jan 9, 2022
1 parent 328c2ee commit f4f9122
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions neomatrix_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,20 @@ uint32_t millisdiff(uint32_t before) {
return((millis()-before) ? (millis()-before): 1);
}

uint16_t text_width(char *text, Adafruit_GFX *gfx = NULL) {
if (!gfx) gfx = matrix;
int16_t dummy;
uint16_t w, h;

gfx->getTextBounds(text, 0, 0, &dummy, &dummy, &w, &h);
return(w);
}

uint16_t text_xcenter(char *text, Adafruit_GFX *gfx = NULL) {
if (!gfx) gfx = matrix;
return((gfx->width() - text_width(text, gfx)) / 2);
}

void matrix_setup(bool initserial=true, int reservemem = 40000) {
reservemem = reservemem; // squelch compiler warning if var is unused.

Expand Down

0 comments on commit f4f9122

Please sign in to comment.