mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14109 from loadrunner/label3
Added line spacing/leading feature to Label
This commit is contained in:
commit
82881bf92f
|
@ -446,6 +446,7 @@ void Label::reset()
|
|||
}
|
||||
_additionalKerning = 0.f;
|
||||
_lineHeight = 0.f;
|
||||
_lineSpacing = 0.f;
|
||||
_maxLineWidth = 0.f;
|
||||
_labelDimensions.width = 0.f;
|
||||
_labelDimensions.height = 0.f;
|
||||
|
@ -1465,6 +1466,20 @@ float Label::getLineHeight() const
|
|||
return _textSprite ? 0.0f : _lineHeight;
|
||||
}
|
||||
|
||||
void Label::setLineSpacing(float height)
|
||||
{
|
||||
if (_lineSpacing != height)
|
||||
{
|
||||
_lineSpacing = height;
|
||||
_contentDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
float Label::getLineSpacing() const
|
||||
{
|
||||
return _lineSpacing;
|
||||
}
|
||||
|
||||
void Label::setAdditionalKerning(float space)
|
||||
{
|
||||
CCASSERT(_currentLabelType != LabelType::STRING_TEXTURE, "Not supported system font!");
|
||||
|
|
|
@ -415,6 +415,9 @@ public:
|
|||
*/
|
||||
float getLineHeight() const;
|
||||
|
||||
void setLineSpacing(float height);
|
||||
float getLineSpacing() const;
|
||||
|
||||
/**
|
||||
* Sets the additional kerning of the Label.
|
||||
*
|
||||
|
@ -554,6 +557,7 @@ protected:
|
|||
|
||||
//layout relevant properties.
|
||||
float _lineHeight;
|
||||
float _lineSpacing;
|
||||
float _additionalKerning;
|
||||
int* _horizontalKernings;
|
||||
bool _lineBreakWithoutSpaces;
|
||||
|
|
|
@ -103,6 +103,7 @@ bool Label::multilineTextWrapByWord()
|
|||
float letterRight = 0.f;
|
||||
|
||||
auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
|
||||
float lineSpacing = _lineSpacing * contentScaleFactor;
|
||||
float highestY = 0.f;
|
||||
float lowestY = 0.f;
|
||||
FontLetterDefinition letterDef;
|
||||
|
@ -117,7 +118,7 @@ bool Label::multilineTextWrapByWord()
|
|||
letterRight = 0.f;
|
||||
lineIndex++;
|
||||
nextWordX = 0.f;
|
||||
nextWordY -= _lineHeight;
|
||||
nextWordY -= _lineHeight + lineSpacing;
|
||||
recordPlaceholderInfo(index, character);
|
||||
index++;
|
||||
continue;
|
||||
|
@ -152,7 +153,7 @@ bool Label::multilineTextWrapByWord()
|
|||
letterRight = 0.f;
|
||||
lineIndex++;
|
||||
nextWordX = 0.f;
|
||||
nextWordY -= _lineHeight;
|
||||
nextWordY -= _lineHeight + lineSpacing;
|
||||
newLine = true;
|
||||
break;
|
||||
}
|
||||
|
@ -196,6 +197,8 @@ bool Label::multilineTextWrapByWord()
|
|||
|
||||
_numberOfLines = lineIndex + 1;
|
||||
_textDesiredHeight = (_numberOfLines * _lineHeight) / contentScaleFactor;
|
||||
if (_numberOfLines > 1)
|
||||
_textDesiredHeight += (_numberOfLines - 1) * _lineSpacing;
|
||||
Size contentSize(_labelWidth, _labelHeight);
|
||||
if (_labelWidth <= 0.f)
|
||||
contentSize.width = longestLine;
|
||||
|
@ -223,6 +226,7 @@ bool Label::multilineTextWrapByChar()
|
|||
float letterRight = 0.f;
|
||||
|
||||
auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
|
||||
float lineSpacing = _lineSpacing * contentScaleFactor;
|
||||
float highestY = 0.f;
|
||||
float lowestY = 0.f;
|
||||
FontLetterDefinition letterDef;
|
||||
|
@ -242,7 +246,7 @@ bool Label::multilineTextWrapByChar()
|
|||
letterRight = 0.f;
|
||||
lineIndex++;
|
||||
nextLetterX = 0.f;
|
||||
nextLetterY -= _lineHeight;
|
||||
nextLetterY -= _lineHeight + lineSpacing;
|
||||
recordPlaceholderInfo(index, character);
|
||||
continue;
|
||||
}
|
||||
|
@ -261,7 +265,7 @@ bool Label::multilineTextWrapByChar()
|
|||
letterRight = 0.f;
|
||||
lineIndex++;
|
||||
nextLetterX = 0.f;
|
||||
nextLetterY -= _lineHeight;
|
||||
nextLetterY -= _lineHeight + lineSpacing;
|
||||
letterPosition.x = letterDef.offsetX / contentScaleFactor;
|
||||
}
|
||||
else
|
||||
|
@ -289,6 +293,8 @@ bool Label::multilineTextWrapByChar()
|
|||
|
||||
_numberOfLines = lineIndex + 1;
|
||||
_textDesiredHeight = (_numberOfLines * _lineHeight) / contentScaleFactor;
|
||||
if (_numberOfLines > 1)
|
||||
_textDesiredHeight += (_numberOfLines - 1) * _lineSpacing;
|
||||
Size contentSize(_labelWidth, _labelHeight);
|
||||
if (_labelWidth <= 0.f)
|
||||
contentSize.width = longestLine;
|
||||
|
|
Loading…
Reference in New Issue