From cddf1835b5e1feb5d16705cd21af860403ce5cbc Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Fri, 9 Dec 2016 21:32:03 +0100 Subject: [PATCH] CTextBox: try to fix getMaxLineWidth() methode If found no linebreak, return value could be too small. Space char simulates a line termination as a workaround to get largest possible width. --- src/gui/widget/textbox.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gui/widget/textbox.cpp b/src/gui/widget/textbox.cpp index c1c17ce60..6c78b4f48 100644 --- a/src/gui/widget/textbox.cpp +++ b/src/gui/widget/textbox.cpp @@ -890,11 +890,17 @@ int CTextBox::getLines(const std::string& text) int CTextBox::getMaxLineWidth(const std::string& text, Font* font) { - // if found no linebreak, return pure size only - if (text.find('\n', 0) == std::string::npos) - return font->getRenderWidth(text.c_str()); + std::string txt = text; + if (txt.find('\n', 0) == std::string::npos){ + /* If found no linebreak, return pure size with additional space char. + * Space char simulates a line termination as a workaround to get + * largest possible width. + */ + txt += ' '; + return font->getRenderWidth(txt.c_str()); + } - std::stringstream in (text); + std::stringstream in (txt); if (!in) return 0;