From 95e8072afac17cb3b59208eaf36bd32d69910259 Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 26 Jan 2015 18:26:59 +0800 Subject: [PATCH] fixed issue #10183 --- cocos/ui/UITextField.cpp | 16 ++++++++++------ .../UITextFieldTest/UITextFieldTest.cpp | 7 ++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 045a3f24d8..b507178e3b 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -599,26 +599,30 @@ void TextField::update(float dt) detachWithIMEEvent(); setDetachWithIME(false); } + if (getAttachWithIME()) { attachWithIMEEvent(); setAttachWithIME(false); } + if (getInsertText()) { + //we update the content size first such that when user call getContentSize() in event callback won't be wrong + _textFieldRendererAdaptDirty = true; + updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); + insertTextEvent(); setInsertText(false); - - _textFieldRendererAdaptDirty = true; - updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); } + if (getDeleteBackward()) { - deleteBackwardEvent(); - setDeleteBackward(false); - _textFieldRendererAdaptDirty = true; updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); + + deleteBackwardEvent(); + setDeleteBackward(false); } } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp index 265af8be64..2619787632 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp @@ -426,7 +426,7 @@ bool UITextFieldTest_PlaceHolderColor::init() Size widgetSize = _widget->getContentSize(); // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create("Set place hold color","fonts/Marker Felt.ttf",32); + _displayValueLabel = Text::create("You should see 16.50000, 34.0000 in the output window the first time you type","fonts/Marker Felt.ttf",12); _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); _uiLayer->addChild(_displayValueLabel); @@ -473,7 +473,12 @@ void UITextFieldTest_PlaceHolderColor::textFieldEvent(Ref *pSender, TextField::E break; case TextField::EventType::INSERT_TEXT: + { _displayValueLabel->setString(String::createWithFormat("insert words")->getCString()); + TextField* textField = dynamic_cast(pSender); + auto& contentSize = textField->getContentSize(); + CCLOG("%f, %f", contentSize.width, contentSize.height); + } break; case TextField::EventType::DELETE_BACKWARD: