adafruit / Adafruit-SSD1331-OLED-Driver-Library-for-Arduino

For 0.96" OLEDs in the Adafruit shop
http://www.adafruit.com/products/684
Other
101 stars 67 forks source link

line wrap in Print::print() #1

Closed wa5znu closed 12 years ago

wa5znu commented 12 years ago

Adafruit_SSD1331::write and hence Print::print() obey \n but do not line-wrap at end of line or screen-wrap at bottom of screen. Adafruit_SSD1331::drawString wraps at end of line, but does not obey \n or screen-wrap at bottom of screen.

This short change to write(c) makes print() obey \n and wrap both X and Y:

#if ARDUINO >= 100
size_t Adafruit_SSD1331::write(uint8_t c) {
#else
void Adafruit_SSD1331::write(uint8_t c) {
#endif
  if (c == '\n') {
    cursor_y += textsize*8;
    cursor_x = 0;
    if (cursor_y >= TFTHEIGHT) cursor_y = 0;
  } else if (c == '\r') {
    // skip em
  } else {
    drawChar(cursor_x, cursor_y, c, textcolor, textsize);
    cursor_x += textsize*6;
    if ((cursor_x+5) > TFTWIDTH) {
      cursor_x = 0;
      cursor_y += textsize*8;
    if (cursor_y >= TFTHEIGHT) cursor_y = 0;
    }
  }
#if ARDUINO >= 100
  return 1;
#endif
}
ladyada commented 12 years ago

i kinda did this on purpose but will think about the change. this code has been shifted to Adafruit_GFX btw