mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 00:41:17 +02:00
CTextBox: add static function to get count of lines from passed text
I'm missing a function that returns current line count outside of a CTextBox object. This could be useful eg. for size calculations before object init etc
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
#ifdef VISUAL_DEBUG
|
#ifdef VISUAL_DEBUG
|
||||||
#include <gui/color_custom.h>
|
#include <gui/color_custom.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#define SCROLL_FRAME_WIDTH 10
|
#define SCROLL_FRAME_WIDTH 10
|
||||||
#define SCROLL_MARKER_BORDER 2
|
#define SCROLL_MARKER_BORDER 2
|
||||||
@@ -870,3 +871,19 @@ bool CTextBox::enableSaveScreen(bool mode)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CTextBox::getLines(const std::string& text)
|
||||||
|
{
|
||||||
|
if (text.empty())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
std::stringstream s (text);
|
||||||
|
if (!s)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
std::string line;
|
||||||
|
while(getline(s, line))
|
||||||
|
count++;
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
@@ -201,10 +201,27 @@ class CTextBox : public sigc::trackable
|
|||||||
inline bool isPainted(void) {if( frameBuffer == NULL) return (false); else return (true);};
|
inline bool isPainted(void) {if( frameBuffer == NULL) return (false); else return (true);};
|
||||||
inline CBox getWindowsPos(void) {return(m_cFrame);};
|
inline CBox getWindowsPos(void) {return(m_cFrame);};
|
||||||
inline int getMaxLineWidth(void) {return(m_nMaxTextWidth);};
|
inline int getMaxLineWidth(void) {return(m_nMaxTextWidth);};
|
||||||
inline int getLines(void) {return(m_nNrOfLines);};
|
|
||||||
inline int getLinesPerPage(void) {return m_nLinesPerPage;};
|
inline int getLinesPerPage(void) {return m_nLinesPerPage;};
|
||||||
inline int getPages(void) {return(m_nNrOfPages);};
|
inline int getPages(void) {return(m_nNrOfPages);};
|
||||||
inline int getBackGroundRadius(void) {return(m_nBgRadius);};
|
inline int getBackGroundRadius(void) {return(m_nBgRadius);};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns count of lines of a passed text.
|
||||||
|
* @param[in] text
|
||||||
|
* @li exepts type std::string
|
||||||
|
* @return count of lines as int
|
||||||
|
* @see getLines()
|
||||||
|
*/
|
||||||
|
static int getLines(const std::string& text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns count of evaluated lines from an existent CTextBox instance.
|
||||||
|
* @return count of lines as int
|
||||||
|
* @see static version getLines()
|
||||||
|
*/
|
||||||
|
int getLines(){return(m_nNrOfLines);}
|
||||||
|
|
||||||
inline void movePosition(int x, int y) {m_cFrame.iX = x; m_cFrame.iY = y;};
|
inline void movePosition(int x, int y) {m_cFrame.iX = x; m_cFrame.iY = y;};
|
||||||
int getFontTextHeight();
|
int getFontTextHeight();
|
||||||
inline int getTextMode() {return m_nMode;};
|
inline int getTextMode() {return m_nMode;};
|
||||||
|
Reference in New Issue
Block a user