diff --git a/cocos/ui/UIEditBox/UIEditBox.cpp b/cocos/ui/UIEditBox/UIEditBox.cpp index 32e4c708df..d87e6a64f4 100644 --- a/cocos/ui/UIEditBox/UIEditBox.cpp +++ b/cocos/ui/UIEditBox/UIEditBox.cpp @@ -268,7 +268,7 @@ void EditBox::setPlaceholderFontName(const char* pFontName) _placeholderFontName = pFontName; if (_editBoxImpl != nullptr) { - _editBoxImpl->setPlaceholderFont(pFontName, _fontSize); + _editBoxImpl->setPlaceholderFont(pFontName, _placeholderFontSize); } } diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp b/cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp index 10859ed70c..364ceb2981 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp @@ -124,7 +124,7 @@ void EditBoxImplCommon::setInactiveText(const char* pText) void EditBoxImplCommon::setFont(const char* pFontName, int fontSize) { - this->setNativeFont(pFontName, fontSize); + this->setNativeFont(pFontName, fontSize * _label->getNodeToWorldAffineTransform().a); if(strlen(pFontName) > 0) { @@ -145,7 +145,7 @@ void EditBoxImplCommon::setFontColor(const Color4B& color) void EditBoxImplCommon::setPlaceholderFont(const char* pFontName, int fontSize) { - this->setNativePlaceholderFont(pFontName, fontSize); + this->setNativePlaceholderFont(pFontName, fontSize * _labelPlaceHolder->getNodeToWorldAffineTransform().a); if( strlen(pFontName) > 0) { @@ -249,7 +249,7 @@ void EditBoxImplCommon::setContentSize(const Size& size) auto director = cocos2d::Director::getInstance(); auto glview = director->getOpenGLView(); - Size controlSize = Size(size.width * glview->getScaleX(),size.height * glview->getScaleY()); + Size controlSize = Size(size.width * glview->getScaleX() * _label->getNodeToWorldAffineTransform().a,size.height * glview->getScaleY() * _label->getNodeToWorldAffineTransform().a); this->setNativeContentSize(controlSize); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp index c6dd7d9a31..81819a5e11 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp @@ -100,17 +100,25 @@ bool UIEditBoxTest::init() addChild(buttonPassword); // bottom + // Add an intermediate Node to test scaling and content size relative to world + _editEmailParent = Node::create(); + _editEmailParent->setScale(0.5); + _editEmailParent->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2-50, visibleOrigin.y+visibleSize.height/4)); + addChild(_editEmailParent); + auto bottomButtonSize = Size(editBoxSize.width, editBoxSize.height + 10); _editEmail = ui::EditBox::create(bottomButtonSize, "extensions/yellow_edit.png"); - _editEmail->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2-50, visibleOrigin.y+visibleSize.height/4)); _editEmail->setPlaceHolder("Email:"); _editEmail->setInputMode(ui::EditBox::InputMode::EMAIL_ADDRESS); _editEmail->setDelegate(this); - addChild(_editEmail); + _editEmailParent->addChild(_editEmail); + //It is required to use setFontSize and setContentSize after adding it to the hierarchy, so that native EditBox get the right size + _editEmail->setFontSize(30); + _editEmail->setContentSize(bottomButtonSize); auto buttonEmail = (ui::Button*)button->clone(); buttonEmail->setTitleText("Multiline"); - buttonEmail->setPosition(_editEmail->getPosition() + Vec2(editBoxSize.width/2 + buttonSize.width/2, 0 )); + buttonEmail->setPosition(_editEmailParent->getPosition() + Vec2(editBoxSize.width/2 + buttonSize.width/2, 0 )); buttonEmail->addClickEventListener([=](Ref* ref){ _editEmail->setInputMode(ui::EditBox::InputMode::ANY); }); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h index c4680c30c6..1a07feed1c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h @@ -47,6 +47,7 @@ protected: cocos2d::ui::EditBox* _editName; cocos2d::ui::EditBox* _editPassword; cocos2d::ui::EditBox* _editEmail; + cocos2d::Node* _editEmailParent; }; #endif /* defined(__cocos2d_tests__UIEditBoxTest__) */