mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 08:21:12 +02:00
CTextBox: add static function to get largest line of passed text
This could be useful eg. for size calculations.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user