This commit is contained in:
andyque 2015-01-26 18:26:59 +08:00
parent d94c26006b
commit 95e8072afa
2 changed files with 16 additions and 7 deletions

View File

@ -599,26 +599,30 @@ void TextField::update(float dt)
detachWithIMEEvent(); detachWithIMEEvent();
setDetachWithIME(false); setDetachWithIME(false);
} }
if (getAttachWithIME()) if (getAttachWithIME())
{ {
attachWithIMEEvent(); attachWithIMEEvent();
setAttachWithIME(false); setAttachWithIME(false);
} }
if (getInsertText()) 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(); insertTextEvent();
setInsertText(false); setInsertText(false);
_textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
} }
if (getDeleteBackward()) if (getDeleteBackward())
{ {
deleteBackwardEvent();
setDeleteBackward(false);
_textFieldRendererAdaptDirty = true; _textFieldRendererAdaptDirty = true;
updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize());
deleteBackwardEvent();
setDeleteBackward(false);
} }
} }

View File

@ -426,7 +426,7 @@ bool UITextFieldTest_PlaceHolderColor::init()
Size widgetSize = _widget->getContentSize(); Size widgetSize = _widget->getContentSize();
// Add a label in which the textfield events will be displayed // 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->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel); _uiLayer->addChild(_displayValueLabel);
@ -473,7 +473,12 @@ void UITextFieldTest_PlaceHolderColor::textFieldEvent(Ref *pSender, TextField::E
break; break;
case TextField::EventType::INSERT_TEXT: case TextField::EventType::INSERT_TEXT:
{
_displayValueLabel->setString(String::createWithFormat("insert words")->getCString()); _displayValueLabel->setString(String::createWithFormat("insert words")->getCString());
TextField* textField = dynamic_cast<TextField*>(pSender);
auto& contentSize = textField->getContentSize();
CCLOG("%f, %f", contentSize.width, contentSize.height);
}
break; break;
case TextField::EventType::DELETE_BACKWARD: case TextField::EventType::DELETE_BACKWARD: