diff --git a/code/daisy-looper/helpers.h b/code/daisy-looper/helpers.h index 3148436d076744a8bd406d439dd79fcd5fd255cc..ef66325e25d825533c04d8aab64c12846f08ef0e 100644 --- a/code/daisy-looper/helpers.h +++ b/code/daisy-looper/helpers.h @@ -5,13 +5,28 @@ #include "Adafruit_GFX.h" extern Adafruit_SH1106G display; -int centeredText(const char *buf, int x, int y, int color) { +int centeredText(const char *buf, int x, int y, int color, int lineheight=8) { int16_t x1, y1; uint16_t w, h; + char *line_pointer = strchr(buf, '\n'); display.setTextColor(color); - display.getTextBounds(buf, 0, 0, &x1, &y1, &w, &h); //calc width of new string - display.setCursor(x - (w / 2), y - (h / 2)); - display.print(buf); + if (!line_pointer) { + display.getTextBounds(buf, 0, 0, &x1, &y1, &w, &h); //calc width of new string + display.setCursor(x - (w / 2), y - (h / 2)); + display.print(buf); + }else { + char *tmp = strdup(buf); + char* d = strtok(tmp, "\n"); + int line = 0; + while (d != NULL) { + display.getTextBounds(d, 0, 0, &x1, &y1, &w, &h); //calc width of new string + display.setCursor(x - (w / 2), y - (h / 2)-lineheight/2 + (line*lineheight)); + display.print(d); + d = strtok(NULL, ","); + line++; + } + free(tmp); + } return w; }