mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +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;
|
||||
}
|
||||
|
@@ -200,7 +200,6 @@ class CTextBox : public sigc::trackable
|
||||
|
||||
inline bool isPainted(void) {if( frameBuffer == NULL) return (false); else return (true);};
|
||||
inline CBox getWindowsPos(void) {return(m_cFrame);};
|
||||
inline int getMaxLineWidth(void) {return(m_nMaxTextWidth);};
|
||||
|
||||
inline int getLinesPerPage(void) {return m_nLinesPerPage;};
|
||||
inline int getPages(void) {return(m_nNrOfPages);};
|
||||
@@ -222,6 +221,24 @@ class CTextBox : public sigc::trackable
|
||||
*/
|
||||
int getLines(){return(m_nNrOfLines);}
|
||||
|
||||
/**
|
||||
* Returns maximal width of passed text
|
||||
* @param[in] text
|
||||
* @li exepts type std::string
|
||||
* @param[in] font
|
||||
* @li exepts font type object
|
||||
* @return width of largest line as int
|
||||
* @see getMaxLineWidth(void)
|
||||
*/
|
||||
static int getMaxLineWidth(const std::string& text, Font* font);
|
||||
|
||||
/**
|
||||
* Returns internal defined maximal line width of an existent CTextBox instance.
|
||||
* @return width of largest line as int
|
||||
* @see static version getMaxLineWidth()
|
||||
*/
|
||||
int getMaxLineWidth() {return(m_nMaxTextWidth);}
|
||||
|
||||
inline void movePosition(int x, int y) {m_cFrame.iX = x; m_cFrame.iY = y;};
|
||||
int getFontTextHeight();
|
||||
inline int getTextMode() {return m_nMode;};
|
||||
|
Reference in New Issue
Block a user