Improved drawtextLines(...)
Now supports newline \n and automatic line break with hyphens, slashes and colons.
This commit is contained in:
@@ -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 line = getFontHeight(flags & 0xFFFF);
|
||||||
coord_t space = getTextWidth(" ", 1, flags);
|
coord_t space = getTextWidth(" ", 1, flags);
|
||||||
coord_t word;
|
coord_t word;
|
||||||
const char * eos = str + strlen(str);
|
const char * nxt = str;
|
||||||
const char * nxt;
|
|
||||||
|
|
||||||
while (str < eos) {
|
while (true) {
|
||||||
nxt = strstr(str, " ");
|
for (bool done = false; !done; nxt++) {
|
||||||
if (!nxt) nxt = eos;
|
switch (nxt[0]) {
|
||||||
|
case '-':
|
||||||
|
case '/':
|
||||||
|
case ':':
|
||||||
|
nxt++;
|
||||||
|
case ' ':
|
||||||
|
case '\n':
|
||||||
|
case '\0':
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nxt--;
|
||||||
word = getTextWidth(str, nxt - str, flags);
|
word = getTextWidth(str, nxt - str, flags);
|
||||||
if (x + word > left + width && x > left) {
|
if (x + word > left + width && x > left) {
|
||||||
x = left;
|
x = left;
|
||||||
y += line;
|
y += line;
|
||||||
}
|
}
|
||||||
if (y + line > top + height) break;
|
if (y + line > top + height) return;
|
||||||
dc->drawSizedText(x, y, str, nxt - str, flags);
|
dc->drawSizedText(x, y, str, nxt - str, flags);
|
||||||
str = nxt + 1;
|
x += word;
|
||||||
x += word + space;
|
switch (nxt[0]) {
|
||||||
|
case '\0':
|
||||||
|
return;
|
||||||
|
case '\n':
|
||||||
|
x = left;
|
||||||
|
y += line;
|
||||||
|
nxt++;
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
x += space;
|
||||||
|
nxt++;
|
||||||
|
}
|
||||||
|
str = nxt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user