mirror of https://github.com/axmolengine/axmol.git
Merge pull request #10090 from Dhilan007/v3-issue10089
Fixed lose the precision of label's dimensions
This commit is contained in:
commit
9f24b9a350
|
@ -245,10 +245,10 @@ Label::Label(FontAtlas *atlas /* = nullptr */, TextHAlignment hAlignment /* = Te
|
|||
, _commonLineHeight(0.0f)
|
||||
, _lineBreakWithoutSpaces(false)
|
||||
, _horizontalKernings(nullptr)
|
||||
, _maxLineWidth(0)
|
||||
, _maxLineWidth(0.0f)
|
||||
, _labelDimensions(Size::ZERO)
|
||||
, _labelWidth(0)
|
||||
, _labelHeight(0)
|
||||
, _labelWidth(0.0f)
|
||||
, _labelHeight(0.0f)
|
||||
, _hAlignment(hAlignment)
|
||||
, _vAlignment(vAlignment)
|
||||
, _currNumLines(-1)
|
||||
|
@ -496,7 +496,7 @@ void Label::setAlignment(TextHAlignment hAlignment,TextVAlignment vAlignment)
|
|||
}
|
||||
}
|
||||
|
||||
void Label::setMaxLineWidth(unsigned int maxLineWidth)
|
||||
void Label::setMaxLineWidth(float maxLineWidth)
|
||||
{
|
||||
if (_labelWidth == 0 && _maxLineWidth != maxLineWidth)
|
||||
{
|
||||
|
@ -505,7 +505,7 @@ void Label::setMaxLineWidth(unsigned int maxLineWidth)
|
|||
}
|
||||
}
|
||||
|
||||
void Label::setDimensions(unsigned int width, unsigned int height)
|
||||
void Label::setDimensions(float width, float height)
|
||||
{
|
||||
if (height != _labelHeight || width != _labelWidth)
|
||||
{
|
||||
|
|
|
@ -183,25 +183,25 @@ public:
|
|||
* The label's max line width be used for force line breaks if the set value not equal zero.
|
||||
* The label's width and max line width has not always to be equal.
|
||||
*/
|
||||
void setMaxLineWidth(unsigned int maxLineWidth);
|
||||
unsigned int getMaxLineWidth() { return _maxLineWidth;}
|
||||
void setMaxLineWidth(float maxLineWidth);
|
||||
float getMaxLineWidth() { return _maxLineWidth; }
|
||||
|
||||
/** Sets the untransformed size of the label.
|
||||
* The label's width be used for text align if the set value not equal zero.
|
||||
* The label's max line width will be equal to the same value.
|
||||
*/
|
||||
void setWidth(unsigned int width) { setDimensions(width,_labelHeight);}
|
||||
unsigned int getWidth() const { return _labelWidth; }
|
||||
void setWidth(float width) { setDimensions(width,_labelHeight);}
|
||||
float getWidth() const { return _labelWidth; }
|
||||
|
||||
/** Sets the untransformed size of the label.
|
||||
* The label's height be used for text align if the set value not equal zero.
|
||||
* The text will display of incomplete when the size of label not enough to support display all text.
|
||||
*/
|
||||
void setHeight(unsigned int height){ setDimensions(_labelWidth,height);}
|
||||
unsigned int getHeight() const { return _labelHeight;}
|
||||
void setHeight(float height){ setDimensions(_labelWidth, height); }
|
||||
float getHeight() const { return _labelHeight; }
|
||||
|
||||
/** Sets the untransformed size of the label in a more efficient way. */
|
||||
void setDimensions(unsigned int width,unsigned int height);
|
||||
void setDimensions(float width, float height);
|
||||
const Size& getDimensions() const{ return _labelDimensions;}
|
||||
|
||||
/** update content immediately.*/
|
||||
|
@ -365,10 +365,10 @@ protected:
|
|||
bool _lineBreakWithoutSpaces;
|
||||
int * _horizontalKernings;
|
||||
|
||||
unsigned int _maxLineWidth;
|
||||
Size _labelDimensions;
|
||||
unsigned int _labelWidth;
|
||||
unsigned int _labelHeight;
|
||||
float _maxLineWidth;
|
||||
Size _labelDimensions;
|
||||
float _labelWidth;
|
||||
float _labelHeight;
|
||||
TextHAlignment _hAlignment;
|
||||
TextVAlignment _vAlignment;
|
||||
|
||||
|
|
|
@ -132,9 +132,9 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
|
|||
lastBreakLocation = i + insertCount;
|
||||
}
|
||||
textSize = [lineBreak sizeWithAttributes:tokenAttributesDict];
|
||||
if(info->height > 0 && textSize.height > info->height)
|
||||
if(info->height > 0 && (int)textSize.height > info->height)
|
||||
break;
|
||||
if (textSize.width > info->width) {
|
||||
if ((int)textSize.width > info->width) {
|
||||
if(lastBreakLocation > 0) {
|
||||
[lineBreak insertString:@"\r" atIndex:lastBreakLocation];
|
||||
lastBreakLocation = 0;
|
||||
|
|
|
@ -84,7 +84,8 @@ static std::function<Layer*()> createFunctions[] =
|
|||
CL(LabelIssue8492Test),
|
||||
CL(LabelMultilineWithOutline),
|
||||
CL(LabelIssue9255Test),
|
||||
CL(LabelSmallDimensionsTest)
|
||||
CL(LabelSmallDimensionsTest),
|
||||
CL(LabelIssue10089Test)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
@ -1895,3 +1896,30 @@ std::string LabelSmallDimensionsTest::subtitle() const
|
|||
{
|
||||
return "Program should not dead loop";
|
||||
}
|
||||
|
||||
LabelIssue10089Test::LabelIssue10089Test()
|
||||
{
|
||||
auto center = VisibleRect::center();
|
||||
|
||||
auto labelA = Label::createWithSystemFont("create label with system font", "fonts/arial.ttf", 24);
|
||||
auto size = labelA->getContentSize();
|
||||
labelA->setDimensions(size.width, size.height);
|
||||
labelA->setPosition(center.x, center.y + 50);
|
||||
addChild(labelA);
|
||||
|
||||
auto labelB = Label::createWithTTF("create label with TTF", "fonts/arial.ttf", 24);
|
||||
size = labelB->getContentSize();
|
||||
labelB->setDimensions(size.width, size.height);
|
||||
labelB->setPosition(center.x, center.y - 50);
|
||||
addChild(labelB);
|
||||
}
|
||||
|
||||
std::string LabelIssue10089Test::title() const
|
||||
{
|
||||
return "Test for Issue #10089";
|
||||
}
|
||||
|
||||
std::string LabelIssue10089Test::subtitle() const
|
||||
{
|
||||
return "Should be able to see two single-line text";
|
||||
}
|
||||
|
|
|
@ -555,5 +555,16 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class LabelIssue10089Test : public AtlasDemoNew
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LabelIssue10089Test);
|
||||
|
||||
LabelIssue10089Test();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue