Improved drawtextLines(...)

Now supports newline \n and automatic line break with hyphens, slashes and colons.
This commit is contained in:
jfrickmann
2021-09-04 06:05:57 -04:00
parent b100d9a164
commit 1db80b31a0
+30 -8
View File
@@ -511,20 +511,42 @@ void drawTextLines(BitmapBuffer * dc, coord_t left, coord_t top, coord_t width,
coord_t line = getFontHeight(flags & 0xFFFF);
coord_t space = getTextWidth(" ", 1, flags);
coord_t word;
const char * eos = str + strlen(str);
const char * nxt;
const char * nxt = str;
while (str < eos) {
nxt = strstr(str, " ");
if (!nxt) nxt = eos;
while (true) {
for (bool done = false; !done; nxt++) {
switch (nxt[0]) {
case '-':
case '/':
case ':':
nxt++;
case ' ':
case '\n':
case '\0':
done = true;
}
}
nxt--;
word = getTextWidth(str, nxt - str, flags);
if (x + word > left + width && x > left) {
x = left;
y += line;
}
if (y + line > top + height) break;
if (y + line > top + height) return;
dc->drawSizedText(x, y, str, nxt - str, flags);
str = nxt + 1;
x += word + space;
x += word;
switch (nxt[0]) {
case '\0':
return;
case '\n':
x = left;
y += line;
nxt++;
break;
case ' ':
x += space;
nxt++;
}
str = nxt;
}
}