From a6b0ea76de95f5208b4a8ee84fbe4a0ec7868453 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Thu, 23 Jun 2016 15:57:41 +0800 Subject: [PATCH] improve editbox test and font creation --- cocos/ui/UIEditBox/UIEditBoxImpl-ios.mm | 3 +++ cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm | 3 +++ .../Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp | 6 +++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-ios.mm b/cocos/ui/UIEditBox/UIEditBoxImpl-ios.mm index 0f8fb66f19..975bbbe28f 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-ios.mm +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-ios.mm @@ -227,6 +227,9 @@ UIFont* EditBoxImplIOS::constructFont(const char *fontName, int fontSize) if (strlen(fontName) > 0) { textFont = [UIFont fontWithName:fntName size:fontSize]; + if (textFont == nil) { + textFont = [UIFont systemFontOfSize:fontSize]; + } } else { diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm b/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm index 3224822309..20c693375e 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm @@ -98,6 +98,9 @@ NSFont* EditBoxImplMac::constructFont(const char *fontName, int fontSize) else { textFont = [NSFont fontWithName:fntName size:fontSize]; + if (textFont == nil) { + textFont = [NSFont systemFontOfSize:fontSize]; + } } return textFont; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp index 517da4dafb..d86510844a 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp @@ -57,13 +57,13 @@ bool UIEditBoxTest::init() // top std::string pNormalSprite = "extensions/green_edit.png"; - _editName = ui::EditBox::create(editBoxSize + Size(0,40), ui::Scale9Sprite::create(pNormalSprite)); - _editName->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2-50, visibleOrigin.y+visibleSize.height*3/4)); + _editName = ui::EditBox::create(editBoxSize + Size(0,20), ui::Scale9Sprite::create(pNormalSprite)); + _editName->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2-60, visibleOrigin.y+visibleSize.height*3/4 - 20)); _editName->setFontColor(Color3B::RED); _editName->setPlaceHolder("Name:"); _editName->setPlaceholderFontColor(Color3B::WHITE); _editName->setMaxLength(8); - _editName->setFontSize(editBoxSize.height/2); + _editName->setFontSize(editBoxSize.height/3); _editName->setText("všŸ‘šŸ‘ŠšŸ’"); _editName->setReturnType(ui::EditBox::KeyboardReturnType::DONE); _editName->setDelegate(this);