From 12df5ae1cc95f53f84d98555523589d256aa6f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dupayrat?= Date: Mon, 16 Nov 2015 17:53:23 +0100 Subject: [PATCH 1/2] Fix wrong variable use for setPlaceholderFontName 1. fix editbox scale not affect native font size --- cocos/ui/UIEditBox/UIEditBox.cpp | 2 +- cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp | 6 +++--- .../UITest/CocoStudioGUITest/UIEditBoxTest.cpp | 14 +++++++++++--- .../UITest/CocoStudioGUITest/UIEditBoxTest.h | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) 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 c44dec4468..1ecc199abb 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..57c0ee3354 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__) */ From 361daf7f5f3f6c4bb9abfa1a3fef57c271d714d6 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 23 Nov 2015 11:48:28 +0800 Subject: [PATCH 2/2] fix wrong indentation --- .../cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h index 57c0ee3354..1a07feed1c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h @@ -47,7 +47,7 @@ protected: cocos2d::ui::EditBox* _editName; cocos2d::ui::EditBox* _editPassword; cocos2d::ui::EditBox* _editEmail; - cocos2d::Node* _editEmailParent; + cocos2d::Node* _editEmailParent; }; #endif /* defined(__cocos2d_tests__UIEditBoxTest__) */