mirror of https://github.com/axmolengine/axmol.git
Merge pull request #10218 from andyque/fixIssue10183
fixed "call ui::TextField getContentSize in insert or delete event callback ,the result is wron"
This commit is contained in:
commit
8d681dfe7d
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<TextField*>(pSender);
|
||||
auto& contentSize = textField->getContentSize();
|
||||
CCLOG("%f, %f", contentSize.width, contentSize.height);
|
||||
}
|
||||
break;
|
||||
|
||||
case TextField::EventType::DELETE_BACKWARD:
|
||||
|
|
Loading…
Reference in New Issue