From c1f25e9c2ae6deaa8c9846ef5eaecb1738851074 Mon Sep 17 00:00:00 2001 From: "Emilien Huet (Malt)" Date: Mon, 22 Dec 2025 06:37:20 -0800 Subject: [PATCH] Add ellipsis on box text --- lib/GfxRenderer/GfxRenderer.cpp | 35 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/GfxRenderer/GfxRenderer.cpp b/lib/GfxRenderer/GfxRenderer.cpp index d70f558..67d40b7 100644 --- a/lib/GfxRenderer/GfxRenderer.cpp +++ b/lib/GfxRenderer/GfxRenderer.cpp @@ -103,27 +103,30 @@ void GfxRenderer::drawTextInBox(const int fontId, const int x, const int y, cons } uint32_t cp; + int ellipsisWidth = 0; while ((cp = utf8NextCodepoint(reinterpret_cast(&text)))) { - // Handle space character for word wrapping - if (cp == ' ') { - if (xpos + spaceWidth > x + w) { + const int charWidth = getTextWidth(fontId, reinterpret_cast(&cp), style); + if (xpos + charWidth + ellipsisWidth > 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; ypos += lineHeight; 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(&cp), style); - if (xpos + charWidth > x + w) { - xpos = x; - ypos += lineHeight; - if (h > 0 && ypos - y > h) { - break; // Exceeded box height } }