esp8266-oled-ssd1306 icon indicating copy to clipboard operation
esp8266-oled-ssd1306 copied to clipboard

drawStringMaxWidth doesn't return 0 even though text fits

Open drount opened this issue 3 years ago • 0 comments

https://github.com/ThingPulse/esp8266-oled-ssd1306/blob/057629d467d6d57a518dcbb0e09726570f1d1940/src/OLEDDisplay.cpp#L716

Hello,

in every drawStringInternal there in an increase in line height so the last check: (yMove + lineNumber * lineHeight) >= this->height()

will always be true if the texts fill all the lines of the screen.

In order to solve, you can break the loop just after drawing the string:

drawStringResult = drawStringInternal(xMove, yMove + (lineNumber++) * lineHeight , &text[lastDrawnPos], preferredBreakpoint - lastDrawnPos, widthAtBreakpoint, true);
if (drawStringResult == 0) // we are past the display already?
        break;
if (firstLineChars == 0)
       firstLineChars = preferredBreakpoint;

and return:

if ((drawStringResult + lastDrawnPos) < length) {
	return firstLineChars ;
}
return 0;

drount avatar Sep 11 '22 18:09 drount