From 8ac1398037e758a8311fcd8c8b7980eee1ca8e72 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 17 Jul 2014 16:23:38 +0800 Subject: [PATCH] fixed text line wrap issue in UITextField. --- cocos/2d/CCLabelTextFormatter.cpp | 2 +- cocos/ui/UITextField.cpp | 19 ++----------------- .../UITextFieldTest/UITextFieldTest.cpp | 3 ++- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index a9658489dd..c1c0c8d386 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -186,7 +186,7 @@ bool LabelTextFormatter::alignText(Label *theLabel) int i = 0; int lineNumber = 0; - int strLen = static_cast(theLabel->_currentUTF16String.length()); + int strLen = theLabel->_limitShowCount; std::vector lastLine; auto strWhole = theLabel->_currentUTF16String; diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 90fb9bc472..8b70bb5297 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -799,24 +799,9 @@ void TextField::adaptRenderers() void TextField::textfieldRendererScaleChangedWithSize() { - if (_ignoreSize) - { - _textFieldRenderer->setDimensions(0,0); - _textFieldRenderer->setScale(1.0f); - } - else + if (!_ignoreSize) { _textFieldRenderer->setDimensions(_contentSize.width, _contentSize.height); - Size textureSize = getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _textFieldRenderer->setScale(1.0f); - return; - } - float scaleX = _contentSize.width / textureSize.width; - float scaleY = _contentSize.height / textureSize.height; - _textFieldRenderer->setScaleX(scaleX); - _textFieldRenderer->setScaleY(scaleY); } _textFieldRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } @@ -871,7 +856,7 @@ void TextField::copySpecialProperties(Widget *widget) void TextField::setTextAreaSize(const Size &size) { - _textFieldRenderer->setDimensions(size.width,size.height); + this->setContentSize(size); } void TextField::setTextHorizontalAlignment(TextHAlignment alignment) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp index 22cbebc1b4..29e14b8389 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp @@ -275,7 +275,8 @@ bool UITextFieldTest_LineWrap::init() // Create the textfield TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30); textField->ignoreContentAdaptWithSize(false); - textField->setContentSize(Size(240, 160)); + ((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true); + textField->setContentSize(Size(240, 70)); textField->setTextHorizontalAlignment(TextHAlignment::CENTER); textField->setTextVerticalAlignment(TextVAlignment::CENTER); textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));