mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-27 01:26:30 +00:00
Added: Minimum lines option to multiline text
This commit is contained in:
parent
9960aab6a1
commit
f5f7a853b9
2 changed files with 54 additions and 3 deletions
|
@ -94,6 +94,7 @@ namespace NLGUI
|
||||||
void setMultiLineClipEndSpace (bool state); // use it for multiline edit box for instance
|
void setMultiLineClipEndSpace (bool state); // use it for multiline edit box for instance
|
||||||
void setFirstLineX (uint firstLineX);
|
void setFirstLineX (uint firstLineX);
|
||||||
void setMultiMaxLine(uint l) { _MultiMaxLine = l; }
|
void setMultiMaxLine(uint l) { _MultiMaxLine = l; }
|
||||||
|
void setMultiMinLine(uint l) { _MultiMinLine = l; }
|
||||||
|
|
||||||
// Force only a subset of letter to be displayed. Default is 0/0xFFFFFFFF
|
// Force only a subset of letter to be displayed. Default is 0/0xFFFFFFFF
|
||||||
void enableStringSelection(uint start, uint end);
|
void enableStringSelection(uint start, uint end);
|
||||||
|
@ -114,6 +115,8 @@ namespace NLGUI
|
||||||
sint getMultiLineSpace() const { return _MultiLineSpace; }
|
sint getMultiLineSpace() const { return _MultiLineSpace; }
|
||||||
bool getMultiLineMaxWOnly() const { return _MultiLineMaxWOnly; }
|
bool getMultiLineMaxWOnly() const { return _MultiLineMaxWOnly; }
|
||||||
uint32 getMultiMaxLine() const { return _MultiMaxLine; }
|
uint32 getMultiMaxLine() const { return _MultiMaxLine; }
|
||||||
|
uint32 getMultiMinLine() const { return _MultiMinLine; }
|
||||||
|
uint32 getMultiMinOffsetY() const;
|
||||||
|
|
||||||
// get current Hint font width, in pixels
|
// get current Hint font width, in pixels
|
||||||
uint getFontWidth() const;
|
uint getFontWidth() const;
|
||||||
|
@ -259,6 +262,7 @@ namespace NLGUI
|
||||||
sint _MultiLineSpace;
|
sint _MultiLineSpace;
|
||||||
sint _LastMultiLineMaxW;
|
sint _LastMultiLineMaxW;
|
||||||
uint32 _MultiMaxLine;
|
uint32 _MultiMaxLine;
|
||||||
|
uint32 _MultiMinLine;
|
||||||
|
|
||||||
|
|
||||||
/// FormatTag handling
|
/// FormatTag handling
|
||||||
|
|
|
@ -75,6 +75,7 @@ namespace NLGUI
|
||||||
_MultiLineMaxWOnly = false;
|
_MultiLineMaxWOnly = false;
|
||||||
_MultiLineClipEndSpace = false;
|
_MultiLineClipEndSpace = false;
|
||||||
_LastMultiLineMaxW = 0;
|
_LastMultiLineMaxW = 0;
|
||||||
|
_MultiMinLine = 0;
|
||||||
_MultiMaxLine = 0;
|
_MultiMaxLine = 0;
|
||||||
_Index = 0xFFFFFFFF;
|
_Index = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
@ -305,6 +306,11 @@ namespace NLGUI
|
||||||
return toString( _MultiMaxLine );
|
return toString( _MultiMaxLine );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
if( name == "multi_min_line" )
|
||||||
|
{
|
||||||
|
return toString( _MultiMinLine );
|
||||||
|
}
|
||||||
|
else
|
||||||
if( name == "underlined" )
|
if( name == "underlined" )
|
||||||
{
|
{
|
||||||
return toString( _Underlined );
|
return toString( _Underlined );
|
||||||
|
@ -479,6 +485,14 @@ namespace NLGUI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
if( name == "multi_min_line" )
|
||||||
|
{
|
||||||
|
uint32 i;
|
||||||
|
if( fromString( value, i ) )
|
||||||
|
_MultiMinLine = i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
if( name == "underlined" )
|
if( name == "underlined" )
|
||||||
{
|
{
|
||||||
bool b;
|
bool b;
|
||||||
|
@ -621,6 +635,7 @@ namespace NLGUI
|
||||||
xmlSetProp( node, BAD_CAST "multi_line_space", BAD_CAST toString( _MultiLineSpace ).c_str() );
|
xmlSetProp( node, BAD_CAST "multi_line_space", BAD_CAST toString( _MultiLineSpace ).c_str() );
|
||||||
xmlSetProp( node, BAD_CAST "multi_line_maxw_only", BAD_CAST toString( _MultiLineMaxWOnly ).c_str() );
|
xmlSetProp( node, BAD_CAST "multi_line_maxw_only", BAD_CAST toString( _MultiLineMaxWOnly ).c_str() );
|
||||||
xmlSetProp( node, BAD_CAST "multi_max_line", BAD_CAST toString( _MultiMaxLine ).c_str() );
|
xmlSetProp( node, BAD_CAST "multi_max_line", BAD_CAST toString( _MultiMaxLine ).c_str() );
|
||||||
|
xmlSetProp( node, BAD_CAST "multi_min_line", BAD_CAST toString( _MultiMinLine ).c_str() );
|
||||||
xmlSetProp( node, BAD_CAST "underlined", BAD_CAST toString( _Underlined ).c_str() );
|
xmlSetProp( node, BAD_CAST "underlined", BAD_CAST toString( _Underlined ).c_str() );
|
||||||
xmlSetProp( node, BAD_CAST "strikethrough", BAD_CAST toString( _StrikeThrough ).c_str() );
|
xmlSetProp( node, BAD_CAST "strikethrough", BAD_CAST toString( _StrikeThrough ).c_str() );
|
||||||
xmlSetProp( node, BAD_CAST "case_mode", BAD_CAST toString( uint32( _CaseMode ) ).c_str() );
|
xmlSetProp( node, BAD_CAST "case_mode", BAD_CAST toString( uint32( _CaseMode ) ).c_str() );
|
||||||
|
@ -741,6 +756,11 @@ namespace NLGUI
|
||||||
if (prop)
|
if (prop)
|
||||||
fromString((const char*)prop, _MultiMaxLine);
|
fromString((const char*)prop, _MultiMaxLine);
|
||||||
|
|
||||||
|
prop = (char*) xmlGetProp( cur, (xmlChar*)"multi_min_line" );
|
||||||
|
_MultiMinLine = 0;
|
||||||
|
if (prop)
|
||||||
|
fromString((const char*)prop, _MultiMinLine);
|
||||||
|
|
||||||
prop = (char*) xmlGetProp( cur, (xmlChar*)"underlined" );
|
prop = (char*) xmlGetProp( cur, (xmlChar*)"underlined" );
|
||||||
_Underlined = false;
|
_Underlined = false;
|
||||||
if (prop)
|
if (prop)
|
||||||
|
@ -981,6 +1001,13 @@ namespace NLGUI
|
||||||
|
|
||||||
sint y_line = _YReal+_FontLegHeight-2;
|
sint y_line = _YReal+_FontLegHeight-2;
|
||||||
|
|
||||||
|
if (_MultiMinLine > _Lines.size())
|
||||||
|
{
|
||||||
|
uint dy = getMultiMinOffsetY();
|
||||||
|
y += dy * ooh;
|
||||||
|
y_line += dy;
|
||||||
|
}
|
||||||
|
|
||||||
// special selection code
|
// special selection code
|
||||||
if(_TextSelection)
|
if(_TextSelection)
|
||||||
{
|
{
|
||||||
|
@ -1360,6 +1387,19 @@ namespace NLGUI
|
||||||
return _FontLegHeight;
|
return _FontLegHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ***************************************************************************
|
||||||
|
uint CViewText::getMultiMinOffsetY() const
|
||||||
|
{
|
||||||
|
uint dy = 0;
|
||||||
|
if (_MultiMinLine > _Lines.size())
|
||||||
|
{
|
||||||
|
// first line is always present even if _Lines is empty
|
||||||
|
uint nbLines = _MultiMinLine - std::max((sint)1, (sint)_Lines.size());
|
||||||
|
dy = nbLines * _FontHeight + (nbLines - 1) * _MultiLineSpace;
|
||||||
|
}
|
||||||
|
return dy;
|
||||||
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CViewText::flushWordInLine(ucstring &ucCurrentWord, bool &linePushed, const CFormatInfo &wordFormat)
|
void CViewText::flushWordInLine(ucstring &ucCurrentWord, bool &linePushed, const CFormatInfo &wordFormat)
|
||||||
{
|
{
|
||||||
|
@ -1836,6 +1876,10 @@ namespace NLGUI
|
||||||
_W = (sint)rTotalW;
|
_W = (sint)rTotalW;
|
||||||
_H = std::max(_FontHeight, uint(_FontHeight * _Lines.size() + std::max(0, sint(_Lines.size()) - 1) * _MultiLineSpace));
|
_H = std::max(_FontHeight, uint(_FontHeight * _Lines.size() + std::max(0, sint(_Lines.size()) - 1) * _MultiLineSpace));
|
||||||
|
|
||||||
|
// See if we should pretend to have at least X lines
|
||||||
|
if (_MultiMinLine > 1)
|
||||||
|
_H = std::max(_H, sint(_FontHeight * _MultiMinLine + (_MultiMinLine - 1) * _MultiLineSpace));
|
||||||
|
|
||||||
// Compute tooltips size
|
// Compute tooltips size
|
||||||
if (_Tooltips.size() > 0)
|
if (_Tooltips.size() > 0)
|
||||||
for (uint i=0 ; i<_Lines.size() ; ++i)
|
for (uint i=0 ; i<_Lines.size() ; ++i)
|
||||||
|
@ -2118,11 +2162,13 @@ namespace NLGUI
|
||||||
//
|
//
|
||||||
if (_MultiLine)
|
if (_MultiLine)
|
||||||
{
|
{
|
||||||
|
uint dy = getMultiMinOffsetY();
|
||||||
|
|
||||||
uint charIndex = 0;
|
uint charIndex = 0;
|
||||||
// special case for end of text
|
// special case for end of text
|
||||||
if (index == (sint) _Text.length())
|
if (index == (sint) _Text.length())
|
||||||
{
|
{
|
||||||
y = 0;
|
y = dy;
|
||||||
if (_Lines.empty())
|
if (_Lines.empty())
|
||||||
{
|
{
|
||||||
x = 0;
|
x = 0;
|
||||||
|
@ -2142,7 +2188,7 @@ namespace NLGUI
|
||||||
{
|
{
|
||||||
// should display the character at the end of previous line
|
// should display the character at the end of previous line
|
||||||
CLine &currLine = *_Lines[i - 1];
|
CLine &currLine = *_Lines[i - 1];
|
||||||
y = (sint) ((_FontHeight + _MultiLineSpace) * (_Lines.size() - i));
|
y = (sint) ((_FontHeight + _MultiLineSpace) * (_Lines.size() - i) + dy);
|
||||||
x = (sint) (currLine.getWidth() + currLine.getEndSpaces() * currLine.getSpaceWidth());
|
x = (sint) (currLine.getWidth() + currLine.getEndSpaces() * currLine.getSpaceWidth());
|
||||||
sint nMaxWidth = getCurrentMultiLineMaxW();
|
sint nMaxWidth = getCurrentMultiLineMaxW();
|
||||||
x = std::min(x, nMaxWidth);
|
x = std::min(x, nMaxWidth);
|
||||||
|
@ -2153,7 +2199,7 @@ namespace NLGUI
|
||||||
if ((sint) newCharIndex > index)
|
if ((sint) newCharIndex > index)
|
||||||
{
|
{
|
||||||
// ok, this line contains the character, now, see which word contains it.
|
// ok, this line contains the character, now, see which word contains it.
|
||||||
y = (sint) ((_FontHeight + _MultiLineSpace) * (_Lines.size() - 1 - i));
|
y = (sint) ((_FontHeight + _MultiLineSpace) * (_Lines.size() - 1 - i) + dy);
|
||||||
// see if the index is in the spaces at the end of line
|
// see if the index is in the spaces at the end of line
|
||||||
if (index - charIndex >= currLine.getNumChars())
|
if (index - charIndex >= currLine.getNumChars())
|
||||||
{
|
{
|
||||||
|
@ -2252,6 +2298,7 @@ namespace NLGUI
|
||||||
uint charPos = 0;
|
uint charPos = 0;
|
||||||
if (_MultiLine)
|
if (_MultiLine)
|
||||||
{
|
{
|
||||||
|
y -= getMultiMinOffsetY();
|
||||||
// seek the line
|
// seek the line
|
||||||
float py = 0.f;
|
float py = 0.f;
|
||||||
if (py > y)
|
if (py > y)
|
||||||
|
|
Loading…
Reference in a new issue