Skip to content

Commit 0de1f07

Browse files
committed
Fixes #61 by calculating strWidth in drawStringMaxWidth correctly
1 parent 27e3686 commit 0de1f07

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

OLEDDisplay.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,17 @@ void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxL
427427
}
428428

429429
if (strWidth >= maxLineWidth) {
430-
preferredBreakpoint = preferredBreakpoint ? preferredBreakpoint : i;
431-
widthAtBreakpoint = preferredBreakpoint ? widthAtBreakpoint : strWidth;
432-
430+
if (preferredBreakpoint == 0) {
431+
preferredBreakpoint = i;
432+
widthAtBreakpoint = strWidth;
433+
}
433434
drawStringInternal(xMove, yMove + (lineNumber++) * lineHeight , &text[lastDrawnPos], preferredBreakpoint - lastDrawnPos, widthAtBreakpoint);
434-
lastDrawnPos = preferredBreakpoint + 1; strWidth = 0; preferredBreakpoint = 0;
435+
lastDrawnPos = preferredBreakpoint + 1;
436+
// It is possible that we did not draw all letters to i so we need
437+
// to account for the width of the chars from `i - preferredBreakpoint`
438+
// by calculating the width we did not draw yet.
439+
strWidth = strWidth - widthAtBreakpoint;
440+
preferredBreakpoint = 0;
435441
}
436442
}
437443

0 commit comments

Comments
 (0)