Add ellipsis on box text

This commit is contained in:
Emilien Huet (Malt) 2025-12-22 06:37:20 -08:00
parent f1056ff9d1
commit c1f25e9c2a

View File

@ -103,27 +103,30 @@ void GfxRenderer::drawTextInBox(const int fontId, const int x, const int y, cons
} }
uint32_t cp; uint32_t cp;
int ellipsisWidth = 0;
while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&text)))) { while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&text)))) {
// Handle space character for word wrapping const int charWidth = getTextWidth(fontId, reinterpret_cast<const char*>(&cp), style);
if (cp == ' ') { if (xpos + charWidth + ellipsisWidth > x + w) {
if (xpos + spaceWidth > x + w) { if (ellipsisWidth > 0) {
// Draw ellipsis and exit
int dotX = xpos;
renderChar(font, '.', &dotX, &ypos, black, style);
dotX += spaceWidth/3;
renderChar(font, '.', &dotX, &ypos, black, style);
dotX += spaceWidth/3;
renderChar(font, '.', &dotX, &ypos, black, style);
break;
} else {
xpos = x; xpos = x;
ypos += lineHeight; ypos += lineHeight;
if (h > 0 && ypos - y > h) { if (h > 0 && ypos - y > h) {
break; // Exceeded box height // Overflowing box height
break;
}
if (h > 0 && ypos + lineHeight - y > h) {
// Last line, prepare ellipsis
ellipsisWidth = spaceWidth * 4;
} }
} else {
xpos += spaceWidth;
}
continue;
}
const int charWidth = getTextWidth(fontId, reinterpret_cast<const char*>(&cp), style);
if (xpos + charWidth > x + w) {
xpos = x;
ypos += lineHeight;
if (h > 0 && ypos - y > h) {
break; // Exceeded box height
} }
} }