1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

fix regression of #6235

This commit is contained in:
Laserlicht
2025-10-24 01:14:37 +02:00
parent 5a650a8f2f
commit 35b294611c

View File

@@ -1671,11 +1671,24 @@ void CObjectListWindow::trimTextIfTooWide(std::string & text) const
int maxWidth = pos.w - 60; // 60 px for scrollbar and borders
auto posBrace = text.find('(');
auto posClosing = text.find(')');
std::string objCount = text.substr(posBrace, posClosing - posBrace) + ')';
if(text[0] == '{')
objCount = '}' + objCount;
std::string objCount;
if (posBrace != std::string::npos && posClosing != std::string::npos && posClosing > posBrace)
{
objCount = text.substr(posBrace, posClosing - posBrace) + ')';
if(text.size() > 0 && text[0] == '{')
objCount = '}' + objCount;
}
else
{
// fallback: if text starts with '{', keep a trailing '}' token, otherwise empty
if(text.size() > 0 && text[0] == '{')
objCount = "}";
else
objCount.clear();
}
const auto & font = ENGINE->renderHandler().loadFont(FONT_SMALL);
std::string suffix = "... " + objCount;
std::string suffix = objCount.empty() ? "..." : std::string("... ") + objCount;
if(font->getStringWidth(text) >= maxWidth)
{