CTextBox: add static function to get largest line of passed text

This could be useful eg. for size calculations.


Origin commit data
------------------
Branch: ni/coolstream
Commit: 91c7588aa6
Author: Thilo Graf <dbt@novatux.de>
Date: 2016-11-10 (Thu, 10 Nov 2016)



------------------
This commit was generated by Migit
This commit is contained in:
2016-11-10 00:30:57 +01:00
parent 75a5b63a4c
commit 0556b53285
2 changed files with 36 additions and 1 deletions

View File

@@ -887,3 +887,21 @@ int CTextBox::getLines(const std::string& text)
return count;
}
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::stringstream in (text);
if (!in)
return 0;
int len = 0;
std::string line;
while(getline(in, line))
len = std::max(len, font->getRenderWidth(line.c_str()));
return len;
}