fix: return text as is if it fits

This commit is contained in:
Arthur Tazhitdinov 2026-02-01 15:23:22 +05:00
parent 68ba5a7f5e
commit 8100858101

View File

@ -419,9 +419,13 @@ std::string GfxRenderer::truncatedText(const int fontId, const char* text, const
std::string item = text; std::string item = text;
const char* ellipsis = "..."; const char* ellipsis = "...";
int ellipsisWidth = getTextWidth(fontId, ellipsis, style); int textWidth = getTextWidth(fontId, item.c_str(), style);
if (textWidth <= maxWidth) {
// Text fits, return as is
return item;
}
while (!item.empty() && getTextWidth(fontId, (item + ellipsis).c_str(), style) > maxWidth) { while (!item.empty() && getTextWidth(fontId, (item + ellipsis).c_str(), style) >= maxWidth) {
utf8RemoveLastChar(item); utf8RemoveLastChar(item);
} }